Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my .Net project built in VS2010, I can retrieve System.Web.HttpContext well
C#
HttpContext httpContext = HttpContext.Current;
string s = httpContext.User.Identity.Name.ToUpper()

But when I switch to VS2015, the value of s is empty. That means the code does not retrieve HttpContext. How can this problem be fixed? Thanks.

What I have tried:

Can't retrieve HttpContext using VS2015
Posted
Updated 20-Dec-19 5:32am
Comments
s yu 20-Dec-19 10:41am    
Refer to https://stackoverflow.com/questions/1056487/httpcontext-current-user-identity-name-is-always-string-empty
Use
string s = System.Web.HttpContext.Current.Request.LogonUserIdentity.Name;
Then the problem is gone. Thanks for your review.
ZurdoDev 20-Dec-19 11:01am    
Please post as solution so that this no longer shows as unanswered.

1 solution

Refer to https://stackoverflow.com/questions/1056487/httpcontext-current-user-identity-name-is-always-string-empty
Use
string s = System.Web.HttpContext.Current.Request.LogonUserIdentity.Name;
Then the problem is gone. Thanks for your review.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900