windows server 2008 + IIS 7.5 下 网站自定义权限过滤问题
本帖最后由 vurtne05112 于 2013-01-05 12:35:46 编辑 网站最近刚刚从 win 2003+ IIS 6 搬迁到 win 2008 r2 + IIS 7.5 的服务器上。
但是我原先正常的自定义用户过滤机制不起作用了,求高手帮忙。
我的用户权限过滤类继承了AuthorizeAttribute类 ,并且重写了OnAuthorization,AuthorizeCore, HandleUnauthorizedRequest 方法 在用户没有权限访问指定页面的时候 我会根据用户类型赋予StatusCode值 进行URL跳转 ,跳转的方式是通过response.write方法 在页面输出 一个带有setTimeout方法的javascript ,但是现在感觉服务器不再执行我的代码,一直在显示服务器默认的错误页面。
我在本机上(win7 + iis 7.5) 也架设了同样的网站,但是不会出现这个问题。
求各位帮忙如何解决这个问题。
网站是用 MVC 3.0 开发的
重写的HandleUnauthorizedRequest代码
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) {
switch (filterContext.HttpContext.Response.StatusCode) {
case 401:
filterContext.HttpContext.Response.Charset = "UTF-8";
//filterContext.HttpContext.Response.Write("<h4 style=\"font-family:微软雅黑;\">" + ErrorMessage + "</h4>");
filterContext.HttpContext.Response.Write("<script>setTimeout(\"document.location='/Home/Index'\",500);</script>");
filterContext.HttpContext.Response.End();
break;
case 403:
string newUrl = string.IsNullOrEmpty(this.AreaName) ? "/Home/Index" : "/" + this.Identity.Identity + "/Index";
filterContext.HttpContext.Response.Charset = "UTF-8";
filterContext.HttpContext.Response.Write("<script>setTimeout(\"document.location='" + newUrl + "'\",200);</script>");
filterContext.HttpContext.Response.End();
break;
default:
base.HandleUnauthorizedRequest(filterContext);
break;
}
}
iis 服务器
------解决方案--------------------
呵呵。
你发现IIS 7.5 比IIS6 多了经典模式和集成模式了吗?
IIS7.5 可以用web.config修改配置,支持修改很多IIS功能。
这个是IIS6没有的。
所以旧版的web.config是不能在iis7.5上面运行注册HttpHandlers、HttpModule。
如果偷懒就设置为经典模式,立马能正常运行了。
[解决办法]
老版本的配置是在 <system.web>下面的
新版本的是在<system.webServer>下面。