asp.net SEO friendly 404 set redirectMode in code

本小妞迷上赌 提交于 2019-12-08 06:53:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!