OWIN上的Application_PreSendRequestHeaders() [英] Application_PreSendRequestHeaders() on OWIN

查看:281
本文介绍了OWIN上的Application_PreSendRequestHeaders()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不使用OWIN中间件的应用程序,并且具有以下Global.asax:

I have an application that does not use OWIN middleware and has the following Global.asax:

public class MvcApplication : HttpApplication
{
     protected void Application_Start()
     {
         //...
     }

     protected void Application_PreSendRequestHeaders()
     {
         Response.Headers.Remove("Server");
     }
}

每次应用程序发送响应时,这都会删除Server标头.

This removes the Server header each time the application sends a response.

如何对使用OWIN的应用程序执行同样的操作?

How can I do the same with an application that uses OWIN?

public class Startup
{
     public void Configuration(IAppBuilder application)
     {
          //...
     }

     //What method do I need to create here?
}

推荐答案

您可以注册IOwinResponse.OnSendingHeaders事件的回调:

You could register a callback for the IOwinResponse.OnSendingHeadersevent:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.Use(async (context, next) =>
        {
            context.Response.OnSendingHeaders(state =>
            {
                ((OwinResponse)state).Headers.Remove("Server");

            }, context.Response);

            await next();
        });

        // Configure the rest of your application...
    }
}

这篇关于OWIN上的Application_PreSendRequestHeaders()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆