Israel Saraiva
Israel Saraiva

Reputation: 155

How to get HttpContext.Current.User.Identity.Name in AspNet 5?

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?

Upvotes: 2

Views: 1354

Answers (1)

Mithun Pattankar
Mithun Pattankar

Reputation: 1372

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

Upvotes: 2

Related Questions