Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.Net无Cookieless新会话Id无限重定向_C#_Asp.net_Session_Redirect - Fatal编程技术网

C# ASP.Net无Cookieless新会话Id无限重定向

C# ASP.Net无Cookieless新会话Id无限重定向,c#,asp.net,session,redirect,C#,Asp.net,Session,Redirect,我遇到了一个无休止的重定向问题。我正试图使每个选项卡获得一个新的会话id。我已通过使用 $.ajax({ type: "POST", url: $('#setSessionUrl').data('url')+'?windowName='+window.name, async: false, success: function (result) { if (result.relocate == false) { var ur

我遇到了一个无休止的重定向问题。我正试图使每个选项卡获得一个新的会话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,但会导致无休止的重定向循环

我已经将其添加到web配置中,但运气不好,因为我注意到fiddler的状态代码是302。我暂时删除了表单验证,但也没有运气

<location path="Views/Login" allowOverride="false">
    <system.web>
      <authorization>
        <allow users="?"/>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
我正在使用无cookieless会话。目标是允许多个会话,而不是注销原始会话

我补充说

context.Response.Redirect(Url.Action("Index"),false);

到我的登录操作,现在它不会无休止地重定向。但是,原始选项卡会被注销。登录这两个选项卡后,我会有单独的会话。如何避免在原始选项卡上注销?

我通过修改操作解决了这个问题

    ViewBag.IgnoreTimeout = true;
    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);
    context.Session["WindowId"] = windowId;
    context.Response.Redirect(Url.Action("Index"),false);
    return View("Index",loginViewModel);
关键是这条线

context.Response.Redirect(Url.Action("Index"),false);

有人能告诉我为什么我必须这样做吗?

我忘了添加我的其他操作,以确定它是否是新窗口[HttpPost]公共操作结果SetSessionId(字符串windowName){if(会话[“WindowId”]==null){Session[“WindowId”]=windowName;返回Json(new{relocate=true});}string window=Session[“WindowId”].ToString();if(window.ToLower()==windowName.ToLower())返回Json(new{relocate=true});返回Json(new{relocate=false});}如果您有更多信息,请编辑您的问题-不要将其作为注释
context.Response.Redirect(Url.Action("Index"),false);