bigyeti bigyeti - 1 month ago 5x
ASP.NET (C#) Question

Why can I not get the UserID with Identity?

In my webforms application, I've taken the Login function from the Login page in the accounts folder, and inserted it into Site.Master.cs so people can login from a drop down form on any page. I want to track logins, so I wanted to take the userid of the person logging in and insert it into a table with a datestamp.
However, with this line of code

string thisuser = User.Identity.GetUserId().ToString();

I'm getting a red line under 'Identity' and the tooltip says "User does not contain a definition for Identity" even though I've included the namespace

using Microsoft.AspNet.Identity;

The frustrating thing is that this works fine elsewhere in a different page.


You should try using System.Web.HttpContext.Current.User.Identity.GetUserId();