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?
Asked
Active
Viewed 2,219 times
1 Answers
2
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.

Dorin
- 2,482
- 2
- 22
- 38
-
`listOf410urls` being an Array? Brilliant. – TheBlackBenzKid Nov 02 '12 at 10:57
-
Well done! I had a few thousand pages that needed to 410. fortunately, it was all pages in a specific directory off the root. I was able to do this: HttpApplication app = sender as HttpApplication; if (app.Request.Url.PathAndQuery.IndexOf("/mydirectory") > -1) {Response.StatusCode = 410; Response.End();} – puddleglum Feb 06 '13 at 20:33
-
one more note... if it was all html pages I need to return as 410, I could have looked for 'html'. That is, as long as ALL html pages are to get a 410 returned. – puddleglum Feb 06 '13 at 20:40