2

How can I get the User.Identity.Name using Asp.Net 5? I have read in stackoverflow answers that HttpContext is not available anymore in this version and people are using HttpContextAccessor, But I have tried to use it and is not working for me, My context returns always null.

Is there any other way to do this? Does anyone suggest returning to Asp.Net 4.5 version?

So, I have some points to consider.. - My application is working normally, But I need to identify the user that is using the system. - I'm using the "domain\user" to store the allowed users on database, and I need to mantain that. - I'm using EntityFramework, AspNet5 and angularjs

Any suggestion?

Israel Saraiva
  • 155
  • 2
  • 10
  • Is [this](http://stackoverflow.com/questions/21362751/user-identity-name-full-name-mvc5) what you are looking for? Also you told you could not access `HttpContextAccessor`. Are you dependency-injecting it? – Siva Gopal Oct 09 '15 at 13:25
  • "Does anyone suggest returning to ASP.NET 4.5?" If you want to use ASP.NET 5, then feel free. Just keep in mind that it's in beta still, not a lot of people have experience with it, and the code and docs are a work in progress. Also, why tag this as AngularJS, when this has nothing to do with the question being asked? – mason Oct 09 '15 at 13:32
  • Thanks for your help Siva! I have read that AspNet Identity doesn't woks with Windows Authentication, because of this i give up to use it. I tried [this](http://stackoverflow.com/questions/28970140/how-properly-inject-httpcontext-in-mvc6), but i see that i need to study dependency-injecting, i don't know it. – Israel Saraiva Oct 09 '15 at 14:26
  • Hello Mason! Thanks for your answer! Yes i agree with you, but my question is based in my experience to solve this problem, I've been searching for an answer in a week. So, i put angularjs because i don't know if there is a way to get user identity from client, maybe. thanks! – Israel Saraiva Oct 09 '15 at 14:30
  • If you are not using AspNet Identity, how are you implementing Windows Authentication? – Stafford Williams Oct 10 '15 at 05:42

1 Answers1

2

I hope you are trying to achieve is windows authentication and access "domain\users" details as User.Identity.Name.

The way authentication works in recent past times or near future is either you store users details in Sql server, Active Directory, Azure or openID etc.

ASP.NET 5 has jumped ahead in getting Identity Management to great extent to leverage infrastructure improvements like Active Directory, SQL Server, Azure; In all these process, ASP.NET 5 has deactivated "Windows Authentication". Check out image, its during creating ASP.NET 5 project from templates

ASP.NET 5 disabled Windows Authentication

Just rethink over using the ASP.NET 5 in terms of User.Identity.Name, I feel its not necessary to move to ASP.NET 4.5 just because of windows authentication disabled, Microsoft provided other better ways to get it done.

Give more inputs on your requirements, we can give better suggestions.

ASP.NET 5 is still in beta, until its production ready use it to learn the skill

Mithun Pattankar
  • 1,372
  • 1
  • 8
  • 12