410 a bunch of html pages in IIS

走远了吗. 提交于 2019-12-11 05:55:17

问题


I need to do a 410 Gone on a bunch of html pages for a site running on IIS. Is there a simple way to do them all at once, like an htaccess file, or do I have to do it one at a time in IIS?


回答1:


I do it this way:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    if( listOf410urls.Contains(Request.RawUrl) )
    {
         Response.StatusCode = 410; Response.End();
    }
}

And then I have in webconfig system.webServer

<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
    <remove statusCode="410" subStatusCode="-1" />
    <error statusCode="410" path="/Error410.aspx" responseMode="ExecuteURL" />
</httpErrors>

This means that all the pages that return 410 will be fetched to the user & search engines using /Error410.aspx page.

In Error410.aspx I also set Response.StatusCode = 410; otherwise the statuscode will be 200 OK.



来源:https://stackoverflow.com/questions/12786994/410-a-bunch-of-html-pages-in-iis

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