【发布时间】:2013-03-21 21:32:58
【问题描述】:
今天我遇到了一个奇怪的问题。 我的网站在 .NET 4 下的应用程序池上运行,今天我们注意到它无法在 IE 10 下对用户进行身份验证(使用其他浏览器一切正常)。这是引发的异常:
“/”应用程序中的服务器错误。
无法转换类型的对象 'System.Security.Principal.GenericIdentity' 键入 'System.Web.Security.FormsIdentity'。描述:一个未处理的 执行当前 Web 请求期间发生异常。 请查看堆栈跟踪以获取有关错误的更多信息和 它起源于代码的地方。
异常详细信息:System.InvalidCastException:无法转换对象 要键入的“System.Security.Principal.GenericIdentity”类型 'System.Web.Security.FormsIdentity'。
但将 .NET 4 升级到 4.5 版后,错误消失了。奇怪的是,我们并没有更改应用程序池上 .NET 的版本,它仍然是 .NET 4。
顺便说一下,我使用的是自定义主体,并且我正在将 userData 附加到 AuthenticationTicket。 这是我来自 Global.asax 的代码:
protected void Application_PostAuthenticateRequest(object sender, EventArgs e)
{
HttpCookie authCooke = Request.Cookies[FormsAuthentication.FormsCookieName];
if (authCooke != null)
{
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCooke.Value);
if (authTicket != null)
{
var identity = new GenericIdentity(authTicket.Name, "Forms");
var principal = new CustomPrincipal(identity);
string userData = ((FormsIdentity)(Context.User.Identity)).Ticket.UserData;
var serializer = new JavaScriptSerializer();
principal.User = (User)serializer.Deserialize(userData, typeof(User));
Context.User = principal;
Thread.CurrentPrincipal = principal;
}
}
}
谁能向我解释我做错了什么以及在不更改应用程序池的情况下更新 .NET 版本会如何影响网站?
【问题讨论】:
标签: asp.net .net asp.net-mvc iis internet-explorer-10