410 a bunch of html pages in IIS

2019-08-12 15:45发布

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条回答
男人必须洒脱
2楼-- · 2019-08-12 16:18

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.

查看更多
登录 后发表回答