Asp.net mvc 4 无法从IE11登录web应用程序
我开发了一个使用表单身份验证和cookie的MVC4 web应用程序。自从我开始(几年)以来,它在所有浏览器中都运行良好 我现在尝试从microsoft虚拟机中使用IE11测试此站点,但登录过程不起作用。当我单击“登录”时,什么也没有发生,我被重定向回登录页面,就好像我没有经过身份验证一样 起初我认为这是因为cookie即将过期,但是cookie正在被设置,因为我可以在临时文件中看到它。我的代码似乎没有做任何棘手的事情 注意:当我将站点添加到兼容性视图时,登录过程正常运行 这是登录/Cookie代码Asp.net mvc 4 无法从IE11登录web应用程序,asp.net-mvc-4,forms-authentication,internet-explorer-11,Asp.net Mvc 4,Forms Authentication,Internet Explorer 11,我开发了一个使用表单身份验证和cookie的MVC4 web应用程序。自从我开始(几年)以来,它在所有浏览器中都运行良好 我现在尝试从microsoft虚拟机中使用IE11测试此站点,但登录过程不起作用。当我单击“登录”时,什么也没有发生,我被重定向回登录页面,就好像我没有经过身份验证一样 起初我认为这是因为cookie即将过期,但是cookie正在被设置,因为我可以在临时文件中看到它。我的代码似乎没有做任何棘手的事情 注意:当我将站点添加到兼容性视图时,登录过程正常运行 这是登录/Cookie
public void SignIn(HttpResponseBase response, string userName, bool rememberMe)
{
if (String.IsNullOrWhiteSpace(userName))
throw new ArgumentException("Value cannot be null or empty.", "userName");
var ticket = new FormsAuthenticationTicket(
1,
userName,
DateTime.Now,
DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes),
rememberMe,
string.Empty);
var cookie = new HttpCookie(
FormsAuthentication.FormsCookieName,
FormsAuthentication.Encrypt(ticket));
cookie.HttpOnly = true;
if (rememberMe)
{
cookie.Expires = ticket.Expiration;
}
response.Cookies.Add(cookie);
}
我已经创建了一个自定义的authorized属性,该属性应该只是向上委派,因为我没有通过ajax进行登录
public class OverseerAuthorizeAttribute : AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext context)
{
if (FormsAuthentication.IsEnabled)
{
if (context.HttpContext.Request.IsAjaxRequest())
{
context.HttpContext.Response.AddHeader("REQUIRES_AUTH", "1");
context.Result = new EmptyResult();
}
else
{
base.HandleUnauthorizedRequest(context);
}
}
else
{
base.HandleUnauthorizedRequest(context);
}
}
}
如果我从控制器中删除authorized属性,那么系统会尝试登录,但由于没有用户名,它会崩溃。当我将其放回时,什么也没有发生。尝试在web.config文件的
表单元素中使用cookieless=“UseCookies”
属性。
这应该可以解决问题。请阅读此处了解更多信息:
太棒了,谢谢。我不能把这周看成是在度假,但我一回来就会去尝试。