开发者

Proper way to abort a web-service request in ASP.NET?

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 t开发者_如何学Gohis 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();
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜