0

I need to retrieve the current logged on User ID in the IIS then I will pass that ID to a function for authentication purpose.

public ActionResult Login(myLoginModel model)
{
            System.Security.Principal.IPrincipal user;
            user = System.Web.HttpContext.Current.User;
            String name = user.Identity.Name.ToString();

AuthenticateUser(name)
}

I always got a null value for "name". My web.config file is:

  <authentication mode="Windows"/>
    <identity impersonate="true"/>

and I have disabled Anonymous Authentication and enabled Windows Authentication on the IIS Manager. Can you help me fix this problem?

user2701646
  • 139
  • 4
  • 4
  • 20
  • possible duplicate of [Windows Authentication - Getting current user name](http://stackoverflow.com/questions/8968254/windows-authentication-getting-current-user-name) -- also, FWIW, by the time they hit "login" they're already authenticated from the AD (unless you're doing something else beyond basic authentication--which should probably happen in `Session_Start`) – Brad Christie Sep 18 '13 at 20:47
  • I tried putting [authorize] on top of my controller method, but it doesn't work. – user2701646 Sep 18 '13 at 20:56

1 Answers1

0

Try to get user not from HttpContext but from Controller directly:

Controller.User.Identity.Name or just User.Identity.Name

Andrey Gubal
  • 3,481
  • 2
  • 18
  • 21