且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET MVC 6(ASP.NET 5)中的Application_PreSendRequestHeaders和Application_BeginRequest

更新时间:2023-02-25 20:36:31

中间件!

public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
{
    app.Use(next => async context =>
    {
        context.Response.Headers.Remove("Server");
        await next.Invoke(context);
    });

    app.Use(next => async context => {
        if (context.Request.Path.ToString().StartsWith("www"))
            await next.Invoke(context);
        else
            context.Response.Redirect("www" + context.Request.Path.ToString());
    });
}

这是一个很好的教程.