我有一个映射到aspnet_isapi.dll的HttpHandler,以便在经典模式下使用IIS7.5对静态文件(.pdf文件)执行自定义身份验证检查:
void IHttpHandler.ProcessRequest(HttpContext context)
{
if(!User.IsMember) {
Response.Redirect("~/Login.aspx?m=1");
}
else {
//serve static content
}
}上面的代码运行良好,除了else语句逻辑。在else语句中,我只是想让StaticFileHandler处理请求,但是我还没能解决这个问题。任何关于如何简单地将文件“移交”回IIS以将请求作为正常的StaticFile请求提供服务的建议都将不胜感激。
发布于 2012-07-07 08:18:30
要直接回答您的问题,您可以创建一个StaticFileHandler并让它处理请求:
// Serve static content:
Type type = typeof(HttpApplication).Assembly.GetType("System.Web.StaticFileHandler", true);
IHttpHandler handler = (IHttpHandler)Activator.CreateInstance(type, true);
handler.ProcessRequest(context);但更好的想法可能是创建一个HTTP模块而不是HTTP处理程序:
public class AuthenticationModule : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication application)
{
application.AuthorizeRequest += this.Application_AuthorizeRequest;
}
private void Application_AuthorizeRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
if (!User.IsMember)
context.Response.Redirect("~/Login.aspx?m=1");
}
}https://stackoverflow.com/questions/11370657
复制相似问题