简体   繁体   English

具有服务客户端作为数据库访问层的ASP.NET MVC 3

[英]ASP.NET MVC 3 with service client as database access layer

I am writing an MVC 3 application, which doens't use the classic approach of accesing the database using the Entity Framework. 我正在编写一个MVC 3应用程序,该应用程序不使用使用实体框架访问数据库的经典方法。 Instead I have another application combined of WCF Services, which are used to manage the database access. 相反,我有另一个由WCF服务组合而成的应用程序,用于管理数据库访问。 Now I want to used those services in my MVC application, as the database access. 现在,我想在我的MVC应用程序中使用这些服务作为数据库访问。 This part is simple. 这部分很简单。 The point where it gets harder is managing authentication and authorization in this scenario. 在这种情况下,更难的是管理身份验证和授权。

For authentication and authorization, I have created custom membership and role providers. 为了进行身份验证和授权,我创建了自定义成员资格和角色提供程序。 I have implemented the necessary methods, but here I have ran into the problem. 我已经实现了必要的方法,但是在这里我遇到了问题。 My services require username and password, to get the list of user roles. 我的服务需要用户名和密码,以获取用户角色列表。

I am wondering how can I store the username and password provided by user on logon, somewhere in the backed of my application, to make sure it is save, and to have the possability to use it in my role provider? 我想知道如何在登录时将用户提供的用户名和密码存储在应用程序支持的某个位置,以确保它已保存并可以在角色提供程序中使用它?

Is session the right choice for this? 会议是正确的选择吗? If so, how can I access user's session in my role provider? 如果是这样,我如何在角色提供程序中访问用户的会话?

You should never use passwords, use password hashes instead (properly salted, of course). 您永远不要使用密码,而应使用密码哈希(当然,应该适当加盐)。 So, now you can pass username and password hash to your role provider which in turn will pass that to your wcf which will grant or not grant the necessary roles. 因此,现在您可以将用户名和密码哈希传递给角色提供者,后者又会将其传递给您的wcf,后者将授予或不授予必要的角色。

Update 更新资料

IsUserInRole method should look like so: IsUserInRole方法应如下所示:

public class WcfRoleProvider: RoleProvider
{
    public bool IsUserInRole(string username, roleName)
    {
        bool result = false;
        using(WcfRoleService roleService = new WcfRoleService())
        {
            result = roleService.IsUserInRole(username, roleName);
        }

        return result;
     }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM