在我的应用程序中,我需要设置一个http响应头.我想在网上做这个.配置.

推荐答案

Solution

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
}

(不要问我为什么要使用此事件,但它确实有效.)

现在,在HttpModule部分的web.config中添加一行:

    <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>

就是这样!

Asp.net相关问答推荐

Reaction-Native SignalR连接在调试模式下工作,在释放模式下失败

ASP.NET Core 延迟加载始终返回 null

如何在 asp.net 服务器中使用字体

如何在 ASP.NET RadioButtonList 中的项目之间添加空格

在 Web.Config 中模拟标签

.Net Framework:w3wp.exe 中的异常

在 ASP.NET 中访问没有值的查询字符串参数

指定的 CGI 应用程序遇到错误,服务器终止了进程

在每页级别增加 ASP.Net 超时

是否可以使用 Membership API 更改用户名

防止 asp.net Web 表单中的跨站点请求伪造 (csrf) 攻击

将 ListItem 的 ASP.NET 列表数据绑定到 DropDownList 问题

Web Api 参数始终为空

如何设置 CSS 切换器

我的 asp.net mvc Web 应用程序中的 OutputCache 设置.防止缓存的多种语法

这个rendersection的代码是什么意思?

如何将参数传递给 ASP.NET MVC 2 中的自定义 ActionFilter?

哪个控件导致了回发?

Docker 中的 ASPNETCORE_ENVIRONMENT

在后面的代码中删除 css 类