davee
davee

Reputation: 156

User.Identity.IsAuthenticated always True

Could someone tell me how to handle the authentication mode @asp.net mvc 3 ? My webconfig has no entry for the tag authentication bcause i dont know which mode is suiteable!

refering to the title:

i'd like to hide some navigations buttons @View, and i tried it with "if (User.Identity.IsAuthenticated)" but thats always true,even if i'm not logged in (on the Website!)

someone an idea?

best regards

Upvotes: 4

Views: 8283

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038930

Since you have remove the <authentication> tag from your web.config it means that you are allowing anonymous access to your site. So anyone is considered as authenticated. That's why IsAuthenticated is always true.

You will need to enable some sort of authentication that you want to use. For example if you want to use Forms Authentication:

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>

So the first thing you will have to decide is how do you intend to manage users and roles. Where do you intend to store them. Once you have decided this it is pretty easy to use either the built-in Membership and Role providers or write custom ones if they don't fit your needs.

I would recommend you start here: http://www.asp.net/mvc/tutorials/older-versions/security/authenticating-users-with-forms-authentication-cs

Upvotes: 5

Related Questions