User.Identity.IsAuthenticated始终为True

dav*_*vee 3 authentication asp.net-mvc web-config

有人能告诉我如何处理验证模式@ asp.net mvc 3?我的webconfig没有标签认证的条目,因为我不知道哪种模式是可以适应的!

参考标题:

我想隐藏一些导航按钮@View,我尝试使用"if(User.Identity.IsAuthenticated)",但这总是正确的,即使我没有登录(在网站上!)

有人有想法?

最好的祝福

Dar*_*rov 5

由于您<authentication>已从web.config中删除标记,因此表示您允许匿名访问您的网站.所以任何人都被认为是经过验证的.这就是为什么IsAuthenticated总是这样true.

您需要启用要使用的某种身份验证.例如,如果要使用表单身份验证:

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
Run Code Online (Sandbox Code Playgroud)

因此,您必须首先决定的是如何管理用户和角色.你打算在哪里储存它们.一旦你决定了它,很容易使用内置的Membership和Role提供者,或者如果它们不符合你的需要就编写自定义的.

我建议你从这里开始:http://www.asp.net/mvc/tutorials/older-versions/security/authenticating-users-with-forms-authentication-cs


归档时间:

查看次数:

5868 次

最近记录:

13 年,7 月 前