I have a .NET web service which is protected by a custom authentication module. The module returns a 403 status code and ends the response (see appendix.)
The authentication module is working as expected, valid authorised users are correctly able to see the properly rendered ASMX content. However, in IIS6 (or the Visual Studio Development Server) the following response is given for unauthorised users;
IIS express (correctly) gives;
(I've not tested this in IIS7, I assume the response would be similar to directly above, I'd be grateful if someone could verify this.)
Looking at the HTTP headers, the 403 status code is being returned to the client alongside the XML Parsing error. I'd like understand why the parsing error is generated (after the response should have been flushed and ended) and how to force the web server to serve a simple 403 response instead.
Appendix
public class IPAuthentication : IHttpModule {
public void Init(HttpApplication application) {
application.AuthenticateRequest += new EventHandler(Application_AuthenticateRequest);
}
private void Application_AuthenticateRequest(object sender, EventArgs e) {
if (!allowed) { //pseudo-code
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.StatusCode = 403;
HttpContext.Current.Response.StatusDescription = "Access denied.";
HttpContext.Current.Response.SuppressContent = true;
HttpContext.Current.Response.End();
}
}
public void Dispose() { }
}