从一个控制器重定向到另一个ASP.NET MVC当会话为null [英] Session is null when redirect from one controller to another ASP.NET MVC

查看:300
本文介绍了从一个控制器重定向到另一个ASP.NET MVC当会话为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么会话为null从一个控制器重定向到另一个?而当我再次刷新页面我发现会话对象不为null且有数据!

第一个控制器:

  HttpContext.Session [SiteCheckpoint] = siteCheckpoint;
//重定向到第二页控制器
的Response.Redirect(?射频=siteCheckpoint.FirstPageUrl ++ referenceId);

第二个控制器:

 如果(HttpContext.Session [Resources.SessionParameter.SiteCheckpoint]!= NULL)
{
    GetCheckpointData();
}
其他
{
    //引发错误页面
}

我试过这个解决方案,但它没有工作:

 <清除NAME =会话/>
<添加名称=会话TYPE =System.Web.SessionState.SessionStateModule/>


解决方案

我解决我的问题,因为我不能确定在我看来,任何模型我无法将任何数据传递给第二个控制器

 <%@页标题=LANGUAGE =C#的MasterPageFile =〜/查看/共享/的Site.Master继承=System.Web.Mvc.ViewPage< BCV4.Web.Redirection.Models.HomeModel>中%GT;

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"/>

解决方案

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>" %>

这篇关于从一个控制器重定向到另一个ASP.NET MVC当会话为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆