我可以通过创建一个WCF服务定制roleprovider? [英] Can I create a custom roleprovider through a WCF service?

查看:157
本文介绍了我可以通过创建一个WCF服务定制roleprovider?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个访问数据库,通过WCF服务的Web应用程序。这个想法是抽象的使用WCF服务Web应用程序中的数据。所有这一切工作正常,但我也用用这确实直接访问ASPNETDB数据库SqlRoleManager内置的roleprovider。我想抽象roleprovider通过创建一个WCF服务定制roleprovider然后通过WCF服务访问它。

I have a web application that accesses a database through a wcf service. The idea is to abstract the data from the web application using the wcf service. All that works fine but I am also using the built in roleprovider using the SqlRoleManager which does access the aspnetdb database directly. I would like to abstract the roleprovider by creating a custom roleprovider in a wcf service and then accessing it through the wcf service.

我已经创建自定义角色提供程序,它工作正常,但现在我需要把它放在一个WCF服务。

I have created the custom role provider and it works fine but now I need to place it in a wcf service.

所以,之前我跳扎进试图让这个工作,通过WCF服务,我在访问roleprovider类,并改变了我的web配置roleprovider参数,使用这个类的Web应用程序创建了第二个类。所以我roleprovider类被称为UcfCstRoleProvider和我的web.config是这样的:

So before I jump headlong into trying to get this to work through the WCF service, I created a second class in the web application that accessed the roleprovider class and changed my web config roleprovider parameters to use that class. So my roleprovider class is called, "UcfCstRoleProvider" and my web.config looks like this:

    <roleManager 
    enabled="true" 
    defaultProvider="UcfCstRoleProvider">
  <providers>
    <add 
        name="UcfCstRoleProvider" 
        type="Ucf.Security.Wcf.WebTests.UcfCstRoleProvider, Ucf.Security.Wcf.WebTests" 
        connectionStringName="SqlRoleManagerConnection" 
        applicationName="SMTP" />
  </providers>
</roleManager>

我上课是这样的:

My class starts like this:

    public class UcfCstRoleProvider : RoleProvider
{
    private readonly WindowsTokenRoleProvider _roleProxy = new WindowsTokenRoleProvider();

    public override string ApplicationName
    {
        get
        {
            return _roleProxy.ApplicationName;
        }
        set
        {
            _roleProxy.ApplicationName = value;
        }
    }

正如我所说的,这工作正常。因此,第二类被称为BlRoleProvider具有相同的属性和参数的roleprovide,但没有实现RoleProvider。我改变web.config中指向此类是这样的:

As I said, this works fine. So the second class is called BlRoleProvider that has identical properties and parameters as the roleprovide but does not implement RoleProvider. I changed the web.config to point to this class like this:

    <roleManager 
    enabled="true" 
    defaultProvider="BlRoleProvider">
  <providers>
    <add 
        name="UcfCstRoleProvider" 
        type="Ucf.Security.Wcf.WebTests.BlRoleProvider, Ucf.Security.Wcf.WebTests" 
        connectionStringName="SqlRoleManagerConnection" 
        applicationName="SMTP" />
  </providers>
</roleManager>

不过,我得到这个错误。 供应商必须实现类的System.Web.Security.RoleProvider'。

But I get this error. "Provider must implement the class 'System.Web.Security.RoleProvider'."

我希望我已经很好地解释足以表明我想做的事情。如果我能得到roleprovider工作,通过另一个类在同一个应用,我相信它会工作,通过WCF服务,但我怎么过去的这个错误?

I hope I have explained well enough to show what I am trying to do. If I can get the roleprovider to work through another class in the same application, I am sure it will work through the WCF service but how do I get past this error?

或者,也许我参加了一个转错了方向,有一个更好的办法做我想做的事情??

Or maybe I took a wrong turn and there is a better way to do what I want to do??

推荐答案

我认为最好的方法是创建一个自定义角色提供并实现每一个方法。在每种方法的实现,调用WCF服务来进行数据访问。例如:

I think your best bet is to create a custom role provider and implement each method. In the implementation of each method, call the WCF service to do the data access. Eg:

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;
     }
}

这篇关于我可以通过创建一个WCF服务定制roleprovider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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