Daniel Harris
Daniel Harris

Reputation: 1905

How do you get Windows user domain/username with C# Razor on IIS 10?

Trying to build a web app that will utilize single-sign-on using Windows authentication with Active Directory. I'm having trouble getting the logged in Windows user domain and username. Things I have tried:

Upvotes: 3

Views: 4241

Answers (2)

grafgenerator
grafgenerator

Reputation: 818

Try the following:

var windowsIdentity = System.Web.HttpContext.Current.User.Identity as WindowsIdentity;

Upvotes: 0

Ted
Ted

Reputation: 4067

You might have to adjust, depending on on the context that you are trying to access the current user

e.g. from a Controller you can do the following:

User.Identity.GetUserId();

make sure that you are using:

using Microsoft.AspNet.Identity;

Upvotes: 2

Related Questions