代码之家  ›  专栏  ›  技术社区  ›  Mister Epic

在ASP。净5

  •  6
  • Mister Epic  · 技术社区  · 10 年前

    如果我想在ASP。NET应用程序,我将在 Global.asax :

    protected void Application_BeginRequest(object sender, EventArgs e)
    { ... }
    

    全局.asax 已从ASP。NET 5.我现在如何处理此类事件?

    2 回复  |  直到 10 年前
        1
  •  3
  •   Community Mohan Dere    8 年前

    在ASP。NET 5是通过中间件实现的。下面是一个示例中间件:

    public class FooMiddleware
    {
        private readonly RequestDelegate _next;
    
        public FooMiddleware(RequestDelegate next)
        {
            _next = next;
        }
    
        public async Task Invoke(HttpContext context)
        {
            // this will run per each request
            // do your stuff and call next middleware inside the chain.
    
            return _next.Invoke(context);
        }
    }
    

    然后,您可以在 Startup 类别:

    public class Startup
    {
        public void Configure(IApplicationBuilder app)
        {
            app.UseMiddleware<FooMiddleware>();
        }
    }
    

    请参阅此处了解 more information on Middlewares in ASP.NET 5 .

    对于任何应用程序启动级别调用,请参阅 application startup documentation .

        2
  •  -2
  •   jomsk1e    10 年前

    ASP。NET应用程序可以不使用global.asax。

    HTTP模块 是global.asax的替代。

    阅读更多信息 here .

    推荐文章