I am creating my own blog engine in MVC3 and I don´t want to register us开发者_开发技巧ers to post comments and other things. I just want to have login page for admin (me) so I don´t want to implement membershipprovider. I just want to have login page and [Authorize] atribute enabled and then logout link. What is best way to do this? Thanks
[Authorize] attribute relies on HttpContext.Current.User IPrinicipal object to verify whether user is authenticated or not. If you don't want to implement MembershipProvider then you will have to implement some type of your own IPrinicipal object. Another solution might be to go with FormsAuthentication with a web.config setting that looks something like this:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880">
<credentials passwordFormat="SHA1">
<user name="admin" password="43206512b209ba29cb5c642edc85bdac133354fe"/> <!-- SecretPass -->
<credentials>
</forms>
</authentication>
Hope this help. Regards.
EDIT: I used online SHA1 hash generator http://hash.online-convert.com/sha1-generator
By using some hard coded password/user name or machine specific login (Admin module is available only a specific IP) is easy.
精彩评论