views:

18

answers:

1

Hi Folks,

We have various web-services which accept requests, but there are periods in the day for some of the services where we do not want to accept requests. (I won't go into why at the moment but it is a requirement).

In these cases I'd like to abort the request as it is being received and am wondering the best way to do this and where is the most appropriate place in the ASP.NET pipeline.

I am currently returning back a status of ServiceUnavailable in the BeginRequest in the global.aspx. Is the the correct way to implement this type of functionality or is there a better alternative. (_webState is an internal variable we use for the current state of the service)

if (_webState != WebStates.Runnable)
{
    Response.StatusCode = (int)System.Net.HttpStatusCode.ServiceUnavailable;
    Response.Write("<p>The Service is not available to accept requests</p>");
    Response.End();
}
+1  A: 

I think the correct way is to create a custom HTTP module as an extension of ASP.NET request handling pipeline. In this module you will be able to refuse connections according to needed strategy. ServiceUnavailable is a standard way of going, we've done this in same way.

But here is exist one very big "but" =). Going this way you can disable only requests that is targeted to ASP.NET application, if you need to refuse all request made to particular application you need to write your custom tool that will stop corresponding ApplicatonPool.

Restuta
Hi Restuata, We currently have a custom module where we implement our own enhanced security, so I can put it in there and see how it works out. Thanks a bunch, Noel
Bigtoe
Happy to help you.
Restuta