我正在开发 ASP.NET MVC 5 应用程序,但在将数据存储到会话时遇到问题。我得到的值始终为空。
这是我设置会话的地方:
string mail = user.Email;
string response = user.CheckEmail();
Session["email"] = mail;
Run Code Online (Sandbox Code Playgroud)
我在这里测试会话,它正在重定向到 YYY:
if ((string)Session["mail"] != null)
{
return RedirectToAction("PPP");
}
else
{
return RedirectToAction("YYY");
}
Run Code Online (Sandbox Code Playgroud)
请立即提供帮助,我们将不胜感激。谢谢
你有错字。
Session["email"] = mail;
if ((string)Session["mail"] != null)
^^^^
Run Code Online (Sandbox Code Playgroud)
会话名称应该是email。此外,您不应强制转换为字符串以检查null。
if (Session["email"] != null)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10134 次 |
| 最近记录: |