This article is a mirror article of machine translation, please click here to jump to the original article.

View: 31098|Reply: 0

[Source] Solved the issue where HttpContext.User.IsInRole() always returns false

[Copy link]
Posted on 2020-6-7 21:19:57 | | |
In the past few days, I have been working on a project with MVC, and I used the HttpContext.User.IsInRole() method, but every time I use it, HttpContext.User.IsInRole("Admin") always returns false. I checked a lot of information on the Internet and found that it was not solved, and if you want to solve it, you must also implement a series of expansion methods. Okay, enough nonsense, officially getting to the topic:



In the above code, HttpContext.User.IsInRole("Admin") returns false. What if we want to return to True?

Add the following methods to Global.asax:



Once added, go to your login page and authorize the current user. Please see:



Well, until now, all the problems have been solved. If you have other good methods, you can share, welcome to leave a message to correct :)

Reprinted from:The hyperlink login is visible.




Previous:The var function of the CSS cascade style sheet
Next:Role-based Authorization
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com