HttpModule を介して静的ファイル Web 要求を処理し、いくつかのポリシーに従って CMS でドキュメントを表示したいと考えています。リクエストを除外することはできますが、asp.net のようにそのようなリクエストを直接処理する方法がわかりません。
2108 次
1 に答える
1
これはあなたが探しているものですか?統合パイプライン モードで実行していると仮定すると、すべてのリクエストがここを通過する必要があるため、許可されていない場合はリクエストを強制終了するか、そうでない場合は通常どおり通過させることができます。
public class MyModule1 : IHttpModule
{
public void Dispose() {}
public void Init(HttpApplication context)
{
context.AuthorizeRequest += context_AuthorizeRequest;
}
void context_AuthorizeRequest(object sender, EventArgs e)
{
var app = (HttpApplication)sender;
// Whatever you want to test to see if they are allowed
// to access this file. I believe the `User` property is
// populated by this point.
if (app.Context.Request.QueryString["allow"] == "1")
{
return;
}
app.Context.Response.StatusCode = 401;
app.Context.Response.End();
}
}
<configuration>
<system.web>
<httpModules>
<add name="CustomSecurityModule" type="MyModule1"/>
</httpModules>
</system.web>
</configuration>
于 2013-03-22T16:20:25.523 に答える