0

I have custom MemberShip. I want in controller to know , who is current user. What I need to add, that show current user?

[BasicHttpAuthorize]
public class TestController : ApiController
{
    public String Get()
    {
        String memb = CustomMembershipProvider.Current.ToString();
        return "Hello " + memb + " From Test Controller!";
    }
}

Unfortunately I do not use login by Windows. So I can't use this method. I need to write a method that through the Entity Framework connects to my database. I can not understand where I can save the current user, which would be in the method of Membership.GetUser () to pull out the current user.

Biseness
  • 25
  • 4

1 Answers1

0
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

or

string userName = Environment.UserName;

Credits to this page: How do I get the current username in .NET using C#?

Community
  • 1
  • 1