After the url of asp.net mvc is rewritten, no page exists and a 302 solution is returned.
Source: Internet
Author: User
Add the following content in web. config:
<System. web>
<CustomErrors mode = "On" redirectMode = "ResponseRewrite"> <! -It must be ResponseRewrite; otherwise, the HTTP header returns HTTPStatusCode or 302->
<Error statusCode = "404" redirect = "/FileNotFound. aspx"/> <! -It must be An aspx file. Although the html file can also be used, the returned StatusCode is 302, and aspx is used to modify the HTTPStatusCode to 404->
</CustomErrors>
</System. web>
Then, create the file FileNotFound. aspx in the root directory of the webpage (according to the file directory indicated by redirect above). The content is as follows:
<% @ Page Language = "C #" Inherits = "System. Web. UI. Page" %>
<Script runat = "server">
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
Response. Status = "404 No Found"; // rewrite StatusCode to 404
}
}
</Script>
<! -The following HTML code can be replaced with the HTML code you want to customize the 404 page->
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/5o/xhtml">
<Head id = "Head1" runat = "server">
<Title> the page does not exist. </title>
</Head>
<Body>
The page does not exist! <A href = "http://www.yourdomain.com"> Click Back </a>
</Body>
</Html>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service