场景:登陆模块
前台代码:
**********************************************************************************************************************************
var url ='/login/CheckUserInfo?UserName=' + $("#UserName").val() + '&Password=' + $("#Password").val()+"&r="+new Date().getTime();
alert(url);
$.ajax({
type: 'POST',
url: url,
success: function (data) {
alert(data.rcode);
if (data.rcode == 1000) {
document.location.href = "/Home/Index";
} else {
$(".error").text(data.rmsg);
}
},
error: function (data) {
alert(data.responseText);
}
});
**********************************************************************************************************************************
运行结果:docunmet.location.href 跳转失败,登陆之后绕回login视图
后台代码:
**********************************************************************************************************************************
public class BaseController : Controller
{
/// <summary>
/// 重新基类在Action执行之前的事情
/// </summary>
/// <param name="filterContext">重写方法的参数</param>
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
//判断用户是否为空
if (string.IsNullOrEmpty(HttpContext.User.Identity.Name))
{
filterContext.Result=RedirectToAction("index","login");
return;
}
}
**********************************************************************************************************************************
将filterContext.Result=RedirectToAction("index","login");改为filterContext.Result=RedirectToAction("index_tell_me_why","login");分析得出
HttpContext.User.Identity出了问题,
HttpContext.User.Identity是在Action“/login/CheckUserInfo”中语句“FormsAuthentication.SetAuthCookie(UserName, false)”生成的;
但是火狐、360浏览器均没问题,IE11怎么就不行呢
最终解决办法参照优快云其他大侠的做法:
**********************************************************************************************************************************
1.添加一个"App_Browsers"文件夹
2.添加一个"*.browser"后缀的文件,如IE10.browser.
3.添加文件内容如下:
<browsers>
<browser refID="Default">
<capabilities><!-- To avoid wrong detections of e.g. IE10 -->
<capability name="cookies" value="true" />
<capability name="ecmascriptversion" value="3.0" />
</capabilities>
</browser>
</browsers>
**********************************************************************************************************************************
前台代码:
**********************************************************************************************************************************
var url ='/login/CheckUserInfo?UserName=' + $("#UserName").val() + '&Password=' + $("#Password").val()+"&r="+new Date().getTime();
alert(url);
$.ajax({
type: 'POST',
url: url,
success: function (data) {
alert(data.rcode);
if (data.rcode == 1000) {
document.location.href = "/Home/Index";
} else {
$(".error").text(data.rmsg);
}
},
error: function (data) {
alert(data.responseText);
}
});
**********************************************************************************************************************************
运行结果:docunmet.location.href 跳转失败,登陆之后绕回login视图
后台代码:
**********************************************************************************************************************************
public class BaseController : Controller
{
/// <summary>
/// 重新基类在Action执行之前的事情
/// </summary>
/// <param name="filterContext">重写方法的参数</param>
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
//判断用户是否为空
if (string.IsNullOrEmpty(HttpContext.User.Identity.Name))
{
filterContext.Result=RedirectToAction("index","login");
return;
}
}
**********************************************************************************************************************************
将filterContext.Result=RedirectToAction("index","login");改为filterContext.Result=RedirectToAction("index_tell_me_why","login");分析得出
HttpContext.User.Identity出了问题,
HttpContext.User.Identity是在Action“/login/CheckUserInfo”中语句“FormsAuthentication.SetAuthCookie(UserName, false)”生成的;
但是火狐、360浏览器均没问题,IE11怎么就不行呢
最终解决办法参照优快云其他大侠的做法:
**********************************************************************************************************************************
1.添加一个"App_Browsers"文件夹
2.添加一个"*.browser"后缀的文件,如IE10.browser.
3.添加文件内容如下:
<browsers>
<browser refID="Default">
<capabilities><!-- To avoid wrong detections of e.g. IE10 -->
<capability name="cookies" value="true" />
<capability name="ecmascriptversion" value="3.0" />
</capabilities>
</browser>
</browsers>
**********************************************************************************************************************************