C# 在Asp.Net 4.0中部署HttpModule时出现问题
我想重写。为此,我编写了一个HttpModule,它在ASP.NET Http模块链中的C# 在Asp.Net 4.0中部署HttpModule时出现问题,c#,asp.net,.net,httpmodule,C#,Asp.net,.net,Httpmodule,我想重写。为此,我编写了一个HttpModule,它在ASP.NET Http模块链中的AuthorizeRequest事件上运行(在HttpHandler处理请求之前) 上下文 我编写了一个抽象类作为基本重写器,它实现了IHttpModule接口: public abstract class BaseModuleRewriter : IHttpModule { public virtual void Init(HttpApplication app) { // WARNING! T
AuthorizeRequest
事件上运行(在HttpHandler处理请求之前)
上下文
我编写了一个抽象类作为基本重写器,它实现了IHttpModule
接口:
public abstract class BaseModuleRewriter : IHttpModule {
public virtual void Init(HttpApplication app) {
// WARNING! This does not work with Windows authentication!
app.AuthorizeRequest += new ventHandler(this.BaseModuleRewriter_AuthorizeRequest);
}
public virtual void Dispose() { }
protected virtual void BaseModuleRewriter_AuthorizeRequest(object sender, EventArgs e) {
HttpApplication app = (HttpApplication)sender;
this.Rewrite(app.Request.Path, app);
}
protected abstract void Rewrite(string requestedPath, HttpApplication app);
}
该模块的实际实现是以下类:
public class ModuleRewriter : BaseModuleRewriter {
protected override void Rewrite(string requestedPath, System.Web.HttpApplication app) {
// Just dummy, if the module works, I should never get to any page other than homepage
UrlRewritingUtils.RewriteUrl(app.Context, "Default.aspx");
}
}
在我的web.config中,我有以下内容:
<configuration>
...
<system.web>
<httpModules>
<add type="ModuleRewriter" name="ModuleRewriter"/>
</httpModules>
</system.web>
...
</configuration>
但是,由于我的东西不是预先编译的,而是完全由Asp.Net管理的,所以我不能指定不同的程序集。是否需要解决这个问题?如果是,怎么办
谢谢根据您的应用池配置(集成模式与经典模式),尝试添加
<system.webServer>
<modules>
<add type="ModuleRewriter" name="ModuleRewriter"/>
</modules>
</system.webServer>
更改应用程序池解决了该问题。我把它改成了集成的,它工作了。哇。。。似乎在工作。。。我会让你知道,至少现在我写的课程中有一些错误!最后我得到了一个响应迅速的应用程序:)
<system.webServer>
<modules>
<add type="ModuleRewriter" name="ModuleRewriter"/>
</modules>
</system.webServer>