【发布时间】: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