ASP MVC 3基本注册/登录/注销在不同的表 [英] ASP MVC 3 Basic Register / Login / Logout on a different table

查看:257
本文介绍了ASP MVC 3基本注册/登录/注销在不同的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了默认的帐户模型和控制器随附默认与标准MVC3应用程序,怎么过,因为我已经首先生成我的数据库。

I have seen the default 'Account' Model and Controller which comes default with a standard MVC3 Application, how ever, as I have generated my Database first.

我已经设计了自己的用户表,我想一个简单的注册/登录/注销实施。

I already have designed my own 'Users' table, which I'd like a simple Registration / Log in / Log out to be implemented.

是否有好的教程,显示我如何做到这一点,或任何建议从自己?非常感谢您的时间。

Are there are good tutorials showing me how to do this or any advice from yourselves? Many thanks for your time.

推荐答案

这很简单。创建类从抽象类派生的MembershipProvider

It's simple. Create your class derived from the abstract class MembershipProvider

public class MyMembershipProvider : MembershipProvider
{

}

在更多:的http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.aspx

执行相同的 RoleProvider 如果你需要它。

Do the same for RoleProvider if you need it.

public class MyRoleProvider : RoleProvider
{

}

在更多: http://msdn.microsoft .COM / EN-US /库/ system.web.security.roleprovider.aspx

实施只有你会使用的方法,这一切。先从的ValidateUser()(<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.validateuser.aspx\" rel=\"nofollow\">http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.validateuser.aspx)

Implement only the methods you will use and that's all. Start with ValidateUser() ( http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.validateuser.aspx)

不要忘了点你的供应商,也就是在这种情况下 MyMembershipProvider 来的web.config中的&LT;&的System.Web GT; &LT;会员和GT; &LT;供应商方式&gt; 部分

Don't forget to point your provider, that is in this case MyMembershipProvider to web.config in <system.web> <membership> <providers> section.

不要在几乎每一个教程/博客文章在那里是做什么复杂的,这是一个简单的任务。

Don't complicated it as in almost every tutorial/blog post out there is doing, it's a simple task.

更新:

在RoleProvider你只需要实现

In the RoleProvider you only need to implement

public override string[] GetAllRoles()
        {
            return RoleRepository.GetAllRoles();
        }

        public override string[] GetRolesForUser(string username)
        {
            return RoleRepository.GetRolesForUser(username);
        }

public override bool IsUserInRole(string username, string roleName)
        {  
            return RoleRepository.IsUserInRole(username, roleName);
        }

在你的MembershipProvider只需要实现

In the MembershipProvider you only need to implement

public override bool ValidateUser(string username, string password)
        {
            return MembershipRepository.IsUserValid(username,password);
        }

您可以随时使用自己的的ValidateUser()法而不管的MembershipProvider方法。

You could always use your own ValidateUser() method regardless of the method in the MembershipProvider.

这篇关于ASP MVC 3基本注册/登录/注销在不同的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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