ASP.NET身份验证失败,IE 10
今天我遇到了奇怪的问题。 我的网站运行在.NET 4下的应用程序池中,今天我们注意到它无法在IE 10下验证用户(其他浏览器一切正常)。以下是抛出的异常:ASP.NET身份验证失败,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版本?
难道这是由于您的代码中存在错误拼写(HttpCookie authCooke)。它应该是“authCookie”吗?
我的网站上的类似问题。身份验证仅通过IE10失败,但在Firefox和IE8,IE9中正常工作。 为了解决我在web.config中
<authentication mode="Forms" >
<forms loginUrl="~/Account/LogOn" timeout="2880" cookieless="UseCookies" />
</authentication>
你有没有相同的例外?如果没有 - 我假设你在这篇文章中讨论过一个问题:http://stackoverflow.com/questions/6983732/ie10-user-agent-causes-asp-net-to-not-send-back-set-cookie -ie10 - 不设定-COO – 2013-06-15 10:26:22
添加的参数无Cookie =“UseCookies”的问题-1'authCooke'仅仅是一个变量名,而它可能_should_是'authCookie'那是无关紧要的。如果OP想要,它可能被称为'fred'。 – DeanOC 2013-03-23 09:45:44