1

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

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

and receive errors below:

Compilation Error

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.

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

Source Error:

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

dailyUnknown
  • 152
  • 12
  • 2
    Why are you even using Session here ? Can't you use `User.Identity.GetUserId` wherever you want `Session["UserID"]` ? – Shyju Jan 15 '16 at 03:01
  • And why is this code in the view, particularly a login view when the user does not even exist yet? –  Jan 15 '16 at 03:06

2 Answers2

0

As you try to perform assignments in Razor, it requires to wrap the code in curly brackers

@{ HttpContext.Current.Session["userID"] = User.Identity.GetUserId().ToString(); }
Felix Cen
  • 733
  • 1
  • 6
  • 24
0

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

Thank you all.

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

dailyUnknown
  • 152
  • 12