ASP.NET MVC 3用户身份验证 [英] ASP.NET MVC 3 User Authentication

查看:113
本文介绍了ASP.NET MVC 3用户身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是一些常用的方法做简单的用户验证(帐号​​登录)?

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:

  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆