为什么应用程序名称没有被设置为我的自定义角色的供应商? [英] Why is the application name not being set for my custom role provider?

查看:142
本文介绍了为什么应用程序名称没有被设置为我的自定义角色的供应商?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个ASP.NET应用程序的自定义角色提供程序。我得出我的课从System.Web.Security.RoleProvider并实现所有抽象方法和属性。我在我的配置用的applicationName提供商在web.config,点菜:

I've implemented a custom role provider for an ASP.NET application. I've derived my class from System.Web.Security.RoleProvider and implemented all the abstract methods and properties. I'm configuring my provider with an applicationName in the web.config, à la:

 <roleManager enabled="true" defaultProvider="CustomRoleProvider">
  <providers>
    <clear/>
    <add name="CustomRoleProvider" type="MvcApplication1.CustomRoleProvider" applicationName="Foo"/>
  </providers>
</roleManager>

不过,我的供应商的ApplicationName属性不被相应的设置。为什么呢?

However, the ApplicationName property of my provider is not being set accordingly. Why?

推荐答案

在除了实现从System.Web.Security.RoleProvider的抽象方法,您还需要重写初始化()方法。在属性不受System.Configuration.ProviderSettings处理web.config中的供应商元,喜欢的applicationName,通过初始化传递到自定义角色提供()。添加以下到您的实现的初始化()将设置自定义角色提供商通过在​​web.config中的applicationName属性提供的值的ApplicationName属性:

In addition to implementing the abstract methods from System.Web.Security.RoleProvider, you also need to override the Initialize() method. Attributes in the provider element in web.config that aren't handled by System.Configuration.ProviderSettings, like applicationName, are passed to the custom role provider via Initialize(). Adding the following to your implementation of Initialize() will set the ApplicationName property of the custom role provider to the value provided by the applicationName attribute in the web.config:

   if (config["applicationName"] != null)
       ApplicationName = config["applicationName"];

这篇关于为什么应用程序名称没有被设置为我的自定义角色的供应商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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