我应该如何在ASP.NET MVC站点中实现用户成员资格?

时间:2021-06-04 03:13:32

I'm creating an ASP.NET MVC site and I need to implement login and membership functionality.

我正在创建一个ASP.NET MVC站点,我需要实现登录和成员身份功能。

Is this something where I roll my own? I already have a members table in my database, should I create a username and password hash field and just check against it? What about keeping the user logged in with a cookie that expires?

这是我自己推出的东西吗?我已经在我的数据库中有一个成员表,我应该创建一个用户名和密码哈希字段,然后检查它吗?如何让用户使用过期的cookie登录?

Is this an instance when you would use ASP.NET's built in Membership service?

当您使用ASP.NET的内置Membership服务时,这是一个实例吗?

ASP.NET MVC neophyte seeks help.

ASP.NET MVC新手寻求帮助。

2 个解决方案

#1


14  

When you create a new ASP.NET MVC site, it already has membership built in. The CodePlex project mentioned in the other reply is only needed in special cases, namely:

当您创建新的ASP.NET MVC站点时,它已经内置了成员资格。在其他答复中提到的CodePlex项目仅在特殊情况下才需要,即:

  • You are using an early beta of the MVC framework, which doesn't have the membership feature.
  • 您正在使用MVC框架的早期测试版,该框架没有成员资格功能。
  • You want to use an authentication system like OpenID, which isn't supported "out-of-the-box" with MVC.
  • 您希望使用像OpenID这样的身份验证系统,这与MVC不支持“开箱即用”。
  • You want membership administration features not included "out-of-the-box"
  • 您希望会员管理功能不包括“开箱即用”

However, like I said, basic membership functionality is already present in an MVC site. Just add the [Authorize] attribute to any action requiring login. This is regular forms authentication, so you configured in Web.config like a non-MVC site (specifying the database, etc.; there's lots of information on the web about this).

但是,正如我所说,基本会员功能已经存在于MVC网站中。只需将[Authorize]属性添加到任何需要登录的操作即可。这是常规表单身份验证,因此您在Web.config中配置了非MVC站点(指定数据库等; Web上有很多关于此的信息)。

A default MVC site will contain an "Account" controller and views which you can customize to fit your needs.

默认MVC站点将包含“帐户”控制器和视图,您可以自定义以满足您的需求。

To answer the obvious question, no, you should not "roll your own." Even if you need custom authentication, it would be better to create a regular ASP.NET membership provider than to create an entirely new membership framework.

要回答这个显而易见的问题,不,你不应该“自己动手”。即使您需要自定义身份验证,创建常规ASP.NET成员资格提供程序比创建全新的成员资格框架更好。

Update: The CodePlex project was updated to work with MVC 1.0

更新:CodePlex项目已更新,可与MVC 1.0配合使用

#2


4  

If you want to use something safe to start off with, either use the new project's template membership or consider using http://www.codeplex.com/MvcMembership.

如果您想使用安全的东西,请使用新项目的模板成员资格或考虑使用http://www.codeplex.com/MvcMembership。

#1


14  

When you create a new ASP.NET MVC site, it already has membership built in. The CodePlex project mentioned in the other reply is only needed in special cases, namely:

当您创建新的ASP.NET MVC站点时,它已经内置了成员资格。在其他答复中提到的CodePlex项目仅在特殊情况下才需要,即:

  • You are using an early beta of the MVC framework, which doesn't have the membership feature.
  • 您正在使用MVC框架的早期测试版,该框架没有成员资格功能。
  • You want to use an authentication system like OpenID, which isn't supported "out-of-the-box" with MVC.
  • 您希望使用像OpenID这样的身份验证系统,这与MVC不支持“开箱即用”。
  • You want membership administration features not included "out-of-the-box"
  • 您希望会员管理功能不包括“开箱即用”

However, like I said, basic membership functionality is already present in an MVC site. Just add the [Authorize] attribute to any action requiring login. This is regular forms authentication, so you configured in Web.config like a non-MVC site (specifying the database, etc.; there's lots of information on the web about this).

但是,正如我所说,基本会员功能已经存在于MVC网站中。只需将[Authorize]属性添加到任何需要登录的操作即可。这是常规表单身份验证,因此您在Web.config中配置了非MVC站点(指定数据库等; Web上有很多关于此的信息)。

A default MVC site will contain an "Account" controller and views which you can customize to fit your needs.

默认MVC站点将包含“帐户”控制器和视图,您可以自定义以满足您的需求。

To answer the obvious question, no, you should not "roll your own." Even if you need custom authentication, it would be better to create a regular ASP.NET membership provider than to create an entirely new membership framework.

要回答这个显而易见的问题,不,你不应该“自己动手”。即使您需要自定义身份验证,创建常规ASP.NET成员资格提供程序比创建全新的成员资格框架更好。

Update: The CodePlex project was updated to work with MVC 1.0

更新:CodePlex项目已更新,可与MVC 1.0配合使用

#2


4  

If you want to use something safe to start off with, either use the new project's template membership or consider using http://www.codeplex.com/MvcMembership.

如果您想使用安全的东西,请使用新项目的模板成员资格或考虑使用http://www.codeplex.com/MvcMembership。