ASP.NET MVC 3用户身份验证 [英] ASP.NET MVC 3 User Authentication
问题描述
什么是一些常用的方法做简单的用户验证(帐号登录)?
What are some of the common methods to do simple user validation (account login)?
此外,你可以为每个区域不同的身份验证方案?
Also, can you have different authentication schemes per area?
修改
我创建一个电子商务网站,将需要有每个用户的保护措施。因此,人们怎么会去这样做?这将需要能够让只有认证用户访问他们的信息。
I am creating an eCommerce site that will need to have protected actions per user. So how would one go about doing this? It will need to be able to let only authenticated users access their information.
推荐答案
您有几种选择,当谈到在MVC做验证:
You have several options when it comes to doing authentication in MVC:
- 内建它MVC表单验证(可在这里教程和 href=\"http://msdn.microsoft.com/en-us/library/ff398049.aspx\">)
- 使用窗体身份验证与饼干在MVC3(链接这里)
- 使用Windows身份验证(了解更多... )
- 混合模式身份验证(使用Windows /窗体身份验证在一起。)
- The built-it MVC Forms Authentication (Tutorial available here and here)
- Using Forms Authentication with Cookies in MVC3 (Link here)
- Using Windows Authentication (Learn more here...)
- Mixed Mode Authentication (Using Windows / Forms Authentication together.)
内置的表单认证可以让您根据角色,除其他事项外,用户可以限制访问你的应用程序的不同区域,这是很容易使用实施<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.authorizeattribute.aspx\">[Authorize]属性。
The built in Forms Authentication can allow you to limit access to different areas of your application based on Role, User among other things and it is quite easy to implement using the [Authorize] attribute.
下面就需要用户先登录:
[Authorize]
public ActionResult YourActionNameGoesHere()
{
}
同样,下面就需要在用户登录并是管理员:
[Authorize(Roles="Administrator")]
public ActionResult YourActionNameGoesHere()
{
}
这些只是完成它的几个方法,你可以看到有很多的不同实现这一点的方法 - 我希望这可能已经摆脱了一点光在帮助你决定
Those were just a few methods of accomplishing it, as you can see there are MANY different methods of accomplishing this - I hope this might have shed a bit of light in helping you decide.
这篇关于ASP.NET MVC 3用户身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!