After a virus attack on a shared server added 180 links to a client's website and I spent hours manually removing them, I would like to thwart any similar future attacks by including a generalized 410 Handler. I began by modifying global.asax.cs to issue a 410 error whenever a query string existed since this application does not use them:
protected void Application_BeginRequest(object sender, EventArgs e)
{
string queryParms = Request.Url.Query;
if (queryParms.Length > 0)
{
Response.StatusCode = 410;
Response.End();
}
}
This worked fine (default error page was displayed) for IE11 and Chrome on my local test machine as well as with IE11 on the shared server; but Chrome displayed a blank page.
My ISP infformed me that a custom error page would resolve this issue and supplied a link to the SO post entitled 410 a bunch of html pages in IIS.
As per the SO post instructions, I created a custom 410Error.aspx page in the root folder and set Response.StatusCode = 410 in the code behind, I modified web.config as the SO example illustrated as follows:
<system.webServer>
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
<remove statusCode="410" subStatusCode="-1" />
<error statusCode="410" path="/Error410.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
I also set Custom Errors to true:
<system.web>
<customErrors mode="On" />
<compilation debug="true" targetFramework="4.0"/>
...
</system.web>
Unfortunately, Chrome still displayed a blank page on the loccal macine and shared server, and IE11 showed the default 410 error page. It seems that IIS could not find the Error410.aspx, so I tried using several different paths, including the absolute path with no luck. What am I missing?