UrlRewriting をしたいです。そのために、ASP.NET Http モジュール チェーンのイベントで実行される HttpModule を作成しました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>
実際、これは MSDN メガジンに投稿された記事からの Url-Rewriting の単純な実装です。単純化しただけですが、アプローチはその1つです。
問題
それは動作しません!私があなたに言ったようにモジュールをデプロイしてページをリクエストすると、反対に、常にDefault.aspx
.
何をすべきか?
追加情報
まず、重要な情報が 1 つあります。私のアプリケーション プールは、フレームワーク 4.0 をターゲットとする統合モードです。
私の Web サイトは編集されていません。つまり、Web サイトをプリコンパイルしていませんが、すべてのコードをApp_Code
ディレクトリに置き、ページが要求されたときに ASP.NET にコンパイルさせます。直接的な結果は、すべてのアセンブリが%sysroot%\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\...
ディレクトリに配置されることです。
assemply も指定して、モジュールが web.config にデプロイされているものをいくつか読みました。
<configuration>
...
<system.web>
<httpModules>
<add type="ModuleRewriter, ModuleRewriterAssembly" name="ModuleRewriter"/>
</httpModules>
</system.web>
...
</configuration>
しかし、私のものはプリコンパイルされていませんが、Asp.Net によって完全に管理されているため、別のアセンブリを指定することはできません。この問題を解決するために必要ですか?もしそうなら、何をすべきか?
ありがとうございました