Earliest inspection of request before entry to application

67 views Asked by At

Before hitting the application itself, is there a way to respond to requests, preferably based on URL, and return a response? Possibly a web.config server (IIS) configuration or a static page kinda like app_offline.

Essentially, this is my scenario: If I receive a request with a specific path (i.e. /hello), I want to straight away return a response and not enter the applicaton.

Is this possible? Is there a way to set a static page that is always served before .NET kicks in (auth, filters, middleware, etc.) kinda like app_offline?

I tried looking at ISAPI filters but it seems overly complex for what I want to do, especially considering our apps are deployed to Azure.

Is there some Azure feature we can leverage?

1

There are 1 answers

1
Brando Zhang On

I suggest you could try to use httphandler to achieve your requirement. You could create a custom http handler which will fired before the web form.

Details about how to create a custom httphanlder, you could refer to below steps:

1.Create a custom class:

public class CustomHanlder : IHttpHandler
{
    public bool IsReusable => true;

    public void ProcessRequest(HttpContext context)
    {
        context.Response.Write("CustomHttpHandler");
       
    }
}

2.Add below settings into web.config

<system.webServer>
    <handlers>
        <add name="CustomHandler" path="hello" type="[YouapplicationNameSpace].CustomHanlder" verb="*"/>
    </handlers>
</system.webServer>

Result:

enter image description here