是否有可能增加响应HTTP标头在web.config中? [英] Is it possible to add response http headers in web.config?
本文介绍了是否有可能增加响应HTTP标头在web.config中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序需要设置一个HTTP响应头。我想这样做在web.config中。
In my application I need to set a http response header. I'd like to do this in web.config.
推荐答案
解决方案
最后,经过长时间的搜寻后,我找到了解决办法。与此code创建一个类:
Solution Finally, after a long search I found the solution. Create a class with this code:
public class myHTTPHeaderModule : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.EndRequest += new EventHandler(context_EndRequest);
}
void context_EndRequest(object sender, EventArgs e)
{
HttpResponse response = HttpContext.Current.Response;
response.AddHeader("Content-Language", "*");
}
#endregion
}
(不要问我为什么要使用这个事件,但它的作品。)
(Don't ask me why to use this event, but it works..)
现在添加一行web.config中的HTTP模块部分:
Now add a line in web.config in the HttpModule section:
<httpModules>
<add type="namespace.myHTTPHeaderModule, assembly name" name="headers" />
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
这就是它!
这篇关于是否有可能增加响应HTTP标头在web.config中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文