我应该如何实现用户成员我的ASP.NET MVC的网站? [英] How should I implement user membership in my ASP.NET MVC site?

查看:105
本文介绍了我应该如何实现用户成员我的ASP.NET MVC的网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个ASP.NET MVC的网站,我需要实现登录和会员功能。

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

这是不是在那里我推出自己的?我已经有一个成员表在我的数据库,我应该创建一个用户名和密码哈希属性,只是对证?怎么样保持与过期的cookie登录的用户?

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?

这是一个实例时,您可以使用ASP.NET内置的会员服务?

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

ASP.NET MVC新手寻求帮助。

ASP.NET MVC neophyte seeks help.

推荐答案

当你创建一个新的ASP.NET MVC网站,它已经成员内置的。在其他答复中提到的codePLEX项目只需要在特殊情况下,即:

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:


  • 您正在使用MVC框架,它​​不具有会员功能的早期测试。

  • 您想要使用的认证系统OpenID的一样,这是不支持乱用的用MVC。

  • 您想会员管理功能不包含外的即用

不过,就像我说的,会员基本功能已经present在MVC的网站。只需添加 [授权] 属性需要登录的任何行动。这是常规的窗体身份验证,因此,您在Web.config中配置如非现场MVC(指定数据库等;还有大量的信息这个在网络上)。

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网站将包含一个户口控制器和看法,你可以定制以满足您的需求。

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

要回答这个明显的问题,不,你不应该滚你自己的。即使你需要自定义的身份验证,这将是最好创建一个常规ASP.NET成员资格提供程序,而不是创建一个全新的会员框架。

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.

更新:借助 codePLEX项目进行了更新,与MVC 1.0工作

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

这篇关于我应该如何实现用户成员我的ASP.NET MVC的网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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