在partialview MVC中获取会话变量错误 [英] Getting errors with session variable in partialview MVC

查看:35
本文介绍了在partialview MVC中获取会话变量错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人请帮忙:我将此声明添加到我的partialview登录页面

Someone please help out: I added this statement to my partialview login page

@HttpContext.Current.Session["userID"] = User.Identity.GetUserId().ToString();

并收到以下错误:

编译错误

描述:在编译服务此请求所需的资源期间发生错误.请查看以下特定错误详细信息并适当修改您的源代码.

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

编译器错误消息:CS1525:无效的表达式术语="

Compiler Error Message: CS1525: Invalid expression term '='

源错误:

第 66 行:#line default第 67 行:#line hidden第 68 行:EndContext("~/Views/Shared/_LoginPartial.cshtml", 73, 37, false);第 69 行:第 70 行:

Line 66: #line default Line 67: #line hidden Line 68: EndContext("~/Views/Shared/_LoginPartial.cshtml", 73, 37, false); Line 69: Line 70:

推荐答案

我只是直接使用 User.Identity.GetUserId 而不是 session 变量.

I just use User.Identity.GetUserId directly instead of session variable.

谢谢大家.

不过,如果有人能解释该错误的含义,我将不胜感激.

Still, I appreciate it if someone can explain what that error means though.

这篇关于在partialview MVC中获取会话变量错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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