http-status-code-404

Problem redirecting 403 Forbidden to 404 Not Found

﹥>﹥吖頭↗ 提交于 2019-11-26 22:56:44
问题 The pertinent part of my .htaccess looks like this: Options -Indexes <FilesMatch include> Order allow,deny Deny from all </FilesMatch> RedirectMatch 404 ^/include(/.*)$ And it's generating the following responses: /include 403 /include/ 404 /include/config.inc 403 I can tell by looking at my pattern that problem is likely in the (/.*) part but everything I have tried gives me the same results; instead of consistently getting 404 I get a 404 for the one case and 403 for everything else. What

ASP.net HTTP 404 - File not found instead of MaxRequestLength exception

时光总嘲笑我的痴心妄想 提交于 2019-11-26 22:45:17
问题 I have a file upload control on my webpage. The maximum request length is set to 8 MB ( maxRequestLength = 8192 ). I also have server validation that throws an error if the file is more than 4MB. The reason that its 8MB in the config is the leverage that's given to the user and also so that the application can be tested. If I upload a file that's 9MB, I get thrown an exception Maximum request length exceeded. , which is fine and working as expected. But when I try to upload a file that's 1GB,

What is the proper way to send an HTTP 404 response from an ASP.NET MVC action?

落花浮王杯 提交于 2019-11-26 22:19:29
问题 If given the route: {FeedName}/{ItemPermalink} ex: /Blog/Hello-World If the item doesn't exist, I want to return a 404. What is the right way to do this in ASP.NET MVC? 回答1: Shooting from the hip (cowboy coding ;-)), I'd suggest something like this: Controller: public class HomeController : Controller { public ActionResult Index() { return new HttpNotFoundResult("This doesn't exist"); } } HttpNotFoundResult: using System; using System.Net; using System.Web; using System.Web.Mvc; namespace

react.js Replace img src onerror

烂漫一生 提交于 2019-11-26 22:15:53
问题 I have a react component that is the detail view from a list. I am trying to replace the image with a default image if the image does not exist and there is a 404 error. I would normally use the onerror method in the img tag but that doesn't seem to be working. I am not sure how to do this with react. Here is my component: import React from 'react'; import {Link} from 'react-router'; import ContactStore from '../stores/ContactStore' import ContactActions from '../actions/ContactActions';

Requests to .htaccess should return 404 instead of 403

江枫思渺然 提交于 2019-11-26 22:04:41
问题 This is sort of a follow-up to Is there a way to force apache to return 404 instead of 403? which suggested RedirectMatch to 404 to accomplish this. It works perfectly fine for most of anything, however if I request: http://example.com/.htaccess I get a 403 and not a 404 if I have (or not) this in my .htaccess file: RedirectMatch 404 ^/\.htaccess$ Is there a way to override the default 403 - Forbidden behavior of apache from inside the .htaccess file itself? 回答1: Just after I posted my

How can I catch a 404?

三世轮回 提交于 2019-11-26 22:00:43
问题 I have the following code: HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "HEAD"; request.Credentials = MyCredentialCache; try { request.GetResponse(); } catch { } How can I catch a specific 404 error? The WebExceptionStatus.ProtocolError can only detect that an error occurred, but not give the exact code of the error. For example: catch (WebException ex) { if (ex.Status != WebExceptionStatus.ProtocolError) { throw ex; } } Is just not useful enough... the

web.xml 404 redirect to servlet, how to get the original URI?

旧街凉风 提交于 2019-11-26 20:42:15
问题 I'm redirecting 404 errors to a servlet via the following in my web.xml. <error-page> <error-code>404</error-code> <location>/notFound.do</location> </error-page> I'd like to log where the request was trying to go, but I'm not getting it from the referrer header: request.getHeader("referer") That shows 'null' if I just hit any old random non-existent page. And request.getRequestURL()/request.getRequestURI() both merely shows the final landing servlet info (I.e., /notFound). Any way to get the

Capture 404 status with jQuery AJAX

喜你入骨 提交于 2019-11-26 20:25:06
问题 I have this code: $.ajax({ cache: false, url: "/Admin/Contents/GetData", data: { accountID: AccountID }, success: function (data) { $('#CityID').html(data); }, error: function (ajaxContext) { alert(ajaxContext.responseText) } }); I am still confused about the ajaxContext and how to capture 404 return codes. However I have another question. I am reading something about coding with success and fail and no longer using error in the recent versions of jQuery. So should I change my code to use

Best way to implement a 404 in ASP.NET

人走茶凉 提交于 2019-11-26 20:17:13
I'm trying to determine the best way to implement a 404 page in a standard ASP.NET web application. I currently catch 404 errors in the Application_Error event in the Global.asax file and redirect to a friendly 404.aspx page. The problem is that the request sees a 302 redirect followed by a 404 page missing. Is there a way to bypass the redirect and respond with an immediate 404 containing the friendly error message? Does a web crawler such as Googlebot care if the request for a non existing page returns a 302 followed by a 404? Zhaph - Ben Duguid Handle this in your Global.asax's OnError

Download the contents of a URL in PHP even if it returns a 404

本小妞迷上赌 提交于 2019-11-26 20:14:17
问题 I want to download the contents of a URL using PHP, even if the HTTP response code is 404. file_get_contents will error out, and I wasn't able to find an answer using Google. How can I do this? 回答1: By default file_get_contents only returns the content of HTTP 200 responses. With curl you get the headers and the content separately. As of PHP 5.0, you can also specify a context for file_get_contents , allowing you to do it without relying on url (See Gordon's answer). 回答2: You have to