自定义角色提供程序未在web服务中触发

本文关键字:服务 web 角色 程序 自定义 | 更新日期: 2023-09-27 18:04:45

<system.web>
    <compilation debug="true"
                 targetFramework="4.0" />
    <httpRuntime requestPathInvalidCharacters="" />
    <authentication mode="Forms" />
    <membership defaultProvider=">
        <providers>
            <clear />
                <add name="ANSMP"
                     type="Test.Authentication.CustomMembershipProvider"
                     connectionStringName="DataConnection" />
         </providers>
    </membership>
    <roleManager enabled="true"
                 defaultProvider="ANSRP">
        <providers >
            <clear />       
                <add connectionStringName="DataConnection"
                     applicationName="/"
                     name="ANSRP"
                     type="Test.Authentication.CustomRoleProvider" />
        </providers>
    </roleManager>
</system.web>
<system.serviceModel>
    <behaviours>
        <serviceBehaviors>
            <behavior name="TestDataBehaviour">
                <serviceCredentials>
                    <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
                                            membershipProviderName="ANSMP"/>
                </serviceCredentials>
                <serviceMetadata httpGetEnabled="true"
                                 httpsGetEnabled="true" />
                <serviceAuthorization principalPermissionMode="UseAspNetRoles"
                                      roleProviderName="ANSRP" />
                <dataContractSerializer ignoreExtensionDataObject="true" />
                <serviceDebug httpHelpPageBinding="webHttpBinding"
                              httpHelpPageBindingConfiguration=""
                              includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviour>
    </behaviors>
</system.serviceModel>

假设我的自定义成员提供者和自定义角色提供者为空(Asin,所有方法throw NotImplementedException);当我尝试使用[PrinciplePermission(SecurityAction.Demand, Role = "Custom")]var b = Thread.CurrentPrincipal.IsInRole("Custom")]

检查角色时,我希望出现错误。

然而,它只是继续返回Access is denied(属性)和false的字段。

使用Membership.GetAllUsers()实际上给我一个NotImplementedError ..但是,当我使用PrincipalPermission属性时,我如何确保它触发我的自定义角色提供程序和自定义成员资格提供程序?

编辑

我已经尝试将, Test.Authentication添加到成员提供者的类型以及角色提供者…

然而目前PrinciplePermission告诉我Request for principal permission failed

编辑2

当检查我的跟踪日志时,我发现如下:

The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.PrincipalPermission
The first permission that failed was:
<IPermission class="System.Security.Permissions.PrincipalPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1">
<Identity Authenticated="true"
Role="Customer"/>
</IPermission>
The demand was for:
<IPermission class="System.Security.Permissions.PrincipalPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1">
<Identity Authenticated="true"
Role="Customer"/>
</IPermission>
The assembly or AppDomain that failed was:
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

我也得到了一些Extension type not found警告

<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Warning">
    <TraceIdentifier>http://msdn.microsoft.com/nl-NL/library/System.ServiceModel.ExtensionTypeNotFound.aspx</TraceIdentifier>
    <Description>Extension type not found.</Description>
    <AppDomain>/LM/W3SVC/1/ROOT/webapi3-6-130082517071825580</AppDomain>
    <ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord">
        <ExtensionName>pollingDuplexHttpBinding</ExtensionName>
        <ExtensionType>System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement, System.ServiceModel.PollingDuplex, version=3.0.0.0, Culture=neutral</ExtensionType>
    </ExtendedData>
</TraceRecord>

自定义角色提供程序未在web服务中触发

经过大量的时间,我发现上面显示的每个人都能正常工作

在客户端,当您创建服务引用时,将创建2个端点(在我们的示例中)。我不知道这是不是标准的)。一个安全,一个…嗯,不安全。

对于使用令牌,我总是使用非安全的…但是为了使用会员提供程序、角色提供程序和用户名密码验证,我需要使用安全端点!