仅登录MVC3中的一个成员

时间:2011-08-02 07:58:09

标签: asp.net-mvc-3 login admin membership

我在MVC3中创建自己的博客引擎,我不想注册用户发表评论和其他内容。我只想拥有admin(me)的登录页面所以我不想实现membershipprovider。我只想要启用登录页面和[授权]属性,然后注销链接。什么是最好的方法呢?感谢

2 个答案:

答案 0 :(得分:1)

[Authorize]属性依赖于HttpContext.Current.User IPrinicipal对象来验证用户是否经过身份验证。如果您不想实现MembershipProvider,那么您将必须实现某种类型的自己的IPrinicipal对象。另一个解决方案可能是使用FormsAuthentication,其web.config设置如下所示:

 <authentication mode="Forms">
    <forms loginUrl="~/Account/LogOn" timeout="2880">
        <credentials passwordFormat="SHA1">
            <user name="admin" password="43206512b209ba29cb5c642edc85bdac133354fe"/> <!-- SecretPass -->
        <credentials>
    </forms>
</authentication>

希望这有帮助。问候。

编辑:我使用在线SHA1哈希生成器http://hash.online-convert.com/sha1-generator

答案 1 :(得分:0)

通过使用一些硬编码的密码/用户名或机器特定的登录(管理模块只有特定的IP)很容易。