【发布时间】:2015-09-15 16:53:57
【问题描述】:
我遇到了无限重定向的问题。我试图让每个选项卡都获得一个新的会话 ID。我使用
完成了这项工作$.ajax({
type: "POST",
url: $('#setSessionUrl').data('url')+'?windowName='+window.name,
async: false,
success: function (result) {
if (result.relocate == false) {
var url = $('#loginUrl').data('url');
window.location = url;
}
},
error: function () {
var url = $('#loginUrl').data('url');
window.location = url;
}
});
我的控制器动作看起来像
LoginViewModel loginViewModel = new LoginViewModel();
SessionIDManager sessionIdManager = new GuidSessionIdManager();
var context = System.Web.HttpContext.Current;
string newId = sessionIdManager.CreateSessionID(context);
bool redirected, isAdded;
sessionIdManager.SaveSessionID(context, newId, out redirected, out isAdded);
if (!string.IsNullOrEmpty(update))
{
loginViewModel.UpdateStatus = update;
}
return View(loginViewModel);
这成功生成了一个新的会话 ID,但它会导致无限的重定向循环。
我已将此添加到网络配置中,但没有运气,因为我注意到提琴手我得到状态代码 302。我暂时删除了表单身份验证,但那里也没有运气
<location path="Views/Login" allowOverride="false">
<system.web>
<authorization>
<allow users="?"/>
<allow users="*"/>
</authorization>
</system.web>
</location>
我的 SetSessionId 操作是这样的
[HttpPost]
public ActionResult SetSessionId(string windowName)
{
if (Session["WindowId"] == null)
{
Session["WindowId"] = windowName;
return Json(new{relocate=true});
}
string window = Session["WindowId"].ToString();
if (window.ToLower()==windowName.ToLower())
return Json(new { relocate = true });
return Json(new { relocate = false ,windowId=windowName});
}
我正在使用无 cookie 会话。目标是允许多个会话而不是注销原始会话。
我加了
context.Response.Redirect(Url.Action("Index"),false);
到我的登录操作,现在它不会无休止地重定向。但是,原始选项卡会被注销。一旦我在两个选项卡上登录,我就会有单独的会话。如何避免在原始选项卡上退出?
【问题讨论】:
-
我忘了添加我的其他操作来确定它是否是一个新窗口 [HttpPost] public ActionResult SetSessionId(string windowName) { if (Session["WindowId"] == null) { Session[ "WindowId"] = 窗口名称;返回 Json(new{relocate=true}); } 字符串窗口 = Session["WindowId"].ToString(); if (window.ToLower()==windowName.ToLower()) return Json(new { relocate = true });返回 Json(new { relocate = false }); }
-
如果您有更多信息,请编辑您的问题 - 不要将其作为评论
标签: c# asp.net session redirect