问题
I am trying to achive the below configuration through code
<customErrors defaultRedirect="GenericError.htm" mode="On"
redirectMode="ResponseRewrite">
<error statusCode="404" redirect="404.aspx"/>
</customErrors>
SEO - Handle 404 errors
if ((ex is HttpException && 404 == ((HttpException)ex).GetHttpCode()))
{
HttpContext.Current.RewritePath("~/404.aspx");
//Response.Redirect("~/404.aspx");
//Server.Transfer("~/404.aspx"); //Error executing child request for
}
Question:
How can I set redirectMode="ResponseRewrite" in programattically here?
I dont want to change the url.
Calling Response.Redirect changes the url to /404.aspx and uses 302 Http Status code.
I set Response.StatusCode=404 in page_load of 404.aspx.
Followed http://weblogs.asp.net/paxer/archive/2010/05/31/asp-net-http-404-and-seo.aspx to implement SEO friendly 404. But via code
Also HttpContext.Current.RewritePath not at all working
Server.Transfer has some errors in Application_Error, check https://stackoverflow.com/a/13344446/1909604
来源:https://stackoverflow.com/questions/22383468/asp-net-seo-friendly-404-set-redirectmode-in-code