问题
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