Session is null when redirect from one controller to another ASP.NET MVC

余生颓废 提交于 2019-12-11 05:03:42

问题


Why Session is null when redirection from one controller to another? And when I refresh the page again I find that the session object is not null and have data!

First controller:

HttpContext.Session["SiteCheckpoint"] = siteCheckpoint;
//redirect to second page controller
Response.Redirect(siteCheckpoint.FirstPageUrl + "?rf =" + referenceId);

Second controller:

if (HttpContext.Session[Resources.SessionParameter.SiteCheckpoint] != null)
{
    GetCheckpointData();
}
else 
{                
    //Raise error page
}

I tried this solution but it didn't work:

<remove name="Session" />
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>

回答1:


i solved my issue since i wasn't define any model in my view i can't pass any data to the second controller

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<BCV4.Web.Redirection.Models.HomeModel>" %>


来源:https://stackoverflow.com/questions/10829728/session-is-null-when-redirect-from-one-controller-to-another-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!