客户使用http://aaa.com/uploads/bb/index.html来请求我的ASP.NET MVC站点。我想确保客户有足够的权限访问该网站,因此我需要抓住请求并处理它。我正在使用IHttpModule
来做到这一点。
public class myHttpModule : IHttpModule {
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
Uri url = application.Context.Request.Url;
string path = url.AbsoluteUri;
}
}
问题是当第二次使用相同的网址请求网站时,HttpModule
无法捕获请求。
答案 0 :(得分:0)
得到了答案!这是关于http缓存的。 我编写如下代码,问题被解决了:
public class myHttpModule : IHttpModule {
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
Uri url = application.Context.Request.Url;
string path = url.AbsoluteUri;
**app.Response.Cache.SetCacheability(HttpCacheability.NoCache);**
}
}