简体   繁体   English

在进入应用程序之前尽早检查请求

[英]Earliest inspection of request before entry to application

Before hitting the application itself, is there a way to respond to requests, preferably based on URL, and return a response?在命中应用本身之前,有没有办法响应请求,最好是基于 URL,并返回响应? Possibly a web.config server (IIS) configuration or a static page kinda like app_offline.可能是 web.config 服务器 (IIS) 配置或类似于 app_offline 的静态页面。

Essentially, this is my scenario: If I receive a request with a specific path (ie /hello), I want to straight away return a response and not enter the applicaton.本质上,这是我的场景:如果我收到带有特定路径(即 /hello)的请求,我想立即返回响应而不是进入应用程序。

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?有没有办法设置一个静态页面,它总是在 .NET 启动(身份验证、过滤器、中间件等)之前提供,有点像 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.我尝试查看 ISAPI 过滤器,但对于我想要做的事情来说似乎过于复杂,尤其是考虑到我们的应用程序已部署到 Azure。

Is there some Azure feature we can leverage?是否有一些我们可以利用的 Azure 功能?

I suggest you could try to use httphandler to achieve your requirement.我建议您可以尝试使用 httphandler 来实现您的要求。 You could create a custom http handler which will fired before the web form.您可以创建一个自定义 http 处理程序,它将在 Web 表单之前触发。

Details about how to create a custom httphanlder, you could refer to below steps:关于如何创建自定义 httphanlder 的详细信息,您可以参考以下步骤:

1.Create a custom class: 1.创建自定义类:

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

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

2.Add below settings into web.config 2.将以下设置添加到web.config

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

Result:结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM