how can I check in my _Layout.cshtml file if the current User is administrator or not?
If he'is administrator some links are visible, if he's not they're not visible..
I tried allready with
@If(User.IsInRole("Administrator"){
Links..
}
This works, but only when you log in again..
If you close the page and open it again, and you stay logged in.. It fails..
With regards to your question, to be able to check your _Layout.cshtml file if the current User is administrator or not, and based on whether or not the said user is a administrator their is restriction access to content.
Look at the following and read through the multiple links that talk about your specific question:
Sand3r
0 Points
8 Posts
check for Role in _Layout
Jan 09, 2013 04:01 PM|LINK
Hello,
how can I check in my _Layout.cshtml file if the current User is administrator or not?
If he'is administrator some links are visible, if he's not they're not visible..
I tried allready with
@If(User.IsInRole("Administrator"){ Links.. }This works, but only when you log in again..
If you close the page and open it again, and you stay logged in.. It fails..
Annyone who has anny suggestions?
grtz Sander
ignatandrei
All-Star
134527 Points
21579 Posts
Moderator
MVP
Re: check for Role in _Layout
Jan 09, 2013 06:28 PM|LINK
Why did you say "fail"?!
Sand3r
0 Points
8 Posts
Re: check for Role in _Layout
Jan 09, 2013 06:44 PM|LINK
I mean if you open the website (login is remembered) again and then click on the page, it keeps loading and after a while you get an error..
grtz Sander
april_123456
Participant
775 Points
246 Posts
Re: check for Role in _Layout
Jan 10, 2013 01:17 AM|LINK
Hello Sand3r.
With regards to your question, to be able to check your _Layout.cshtml file if the current User is administrator or not, and based on whether or not the said user is a administrator their is restriction access to content.
Look at the following and read through the multiple links that talk about your specific question:
http://asp.net.bigresource.com/MVC-Access-to-User-Identity-in-Controller-constructor--iMnO1S2ZD.html
Hopefully, this helps you.
Best of Luck,
With Kind Regards,
ignatandrei
All-Star
134527 Points
21579 Posts
Moderator
MVP
Re: check for Role in _Layout
Jan 10, 2013 03:32 AM|LINK
What error?