【问题标题】:HTTP Module for Javascript application IIS用于 Javascript 应用程序 IIS 的 HTTP 模块
【发布时间】:2018-03-11 06:33:56
【问题描述】:

IIS HTTP 模块只能为 IIS 中的 ASP.Net/MVC 应用程序配置吗?因为我有 Angular 2 应用程序(仅限 Html 和 js)并将其部署在 IIS 中,所以它运行良好,但我需要在访问 Angular 应用程序 URL 时读取请求标头。

所以,我正在考虑创建一个像 link 这样提到的 HTTP 模块

在我的 Angular 应用程序 web.config 文件中,创建了一个模块元素,如下所示。

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="AngularJS" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>
        <modules>
            <add name="MyModule" type="SiteMinderTokenReader.MyModule" />
        </modules>
  </system.webServer>
</configuration>

但模块无法按预期工作

这是我的模块代码。

namespace SiteMinderTokenHandler
{
    public class MyModule : IHttpModule
    {
        public void Dispose()
        {

        }

        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
            context.EndRequest += new EventHandler(context_EndRequest);
        }

        void context_BeginRequest(object sender, EventArgs e)
        {

            HttpApplication httpApplication = (HttpApplication)sender;
            httpApplication.Context.Response.Write("<h1>The header....</h1>");
        }

        void context_EndRequest(object sender, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)sender;
            httpApplication.Context.Response.Write("<h6>The footer....</h6>");
        }

    }
}

【问题讨论】:

  • 你的意思是你的模块没有运行??
  • @UmarKarimabadi:是的,它没有运行。

标签: angular iis httpmodule


【解决方案1】:

您的模块未运行,因为您提供的是静态内容。为了使您的模块针对所有内容运行,您需要添加此属性。

<modules runAllManagedModulesForAllRequests="true">
   <add name="MyModule" type="SiteMinderTokenReader.MyModule"/>
</modules>

runAllManagedModulesForAllRequests="true"

这将为所有请求(甚至是静态内容)运行您的模块。另外,请确保您的“类型”正确。包括完整的命名空间。

【讨论】:

  • 我在这里包含了我的模块代码,这就是我更改 web.config 文件的方式。
猜你喜欢
  • 2013-09-27
  • 2016-11-07
  • 1970-01-01
  • 2013-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-09
  • 2016-11-17
相关资源
最近更新 更多