SqlRoleProvider: NullReferenceException when calling Roles.GetRolesForUser

吃可爱长大的小学妹 提交于 2019-12-05 04:54:06
Obelix

blergh

Googling with the tags Stack Overflow provided I came across this site: http://www.lhotka.net/weblog/CallingRolesGetRolesForUserInAWCFService.aspx

In short: apparently something broke between .net 3.5 and .net 4.

To solve this issue call:

string[] roles = Roles.Provider.GetRolesForUser(ServiceSecurityContext.Current.PrimaryIdentity.Name);

instead of

string[] roles = Roles.GetRolesForUser(ServiceSecurityContext.Current.PrimaryIdentity.Name);

The difference is in the .Provider which is added in the middle. After adding this it worked fine.

This issue sounds like this asp.net bug.

connect.microsoft.com

A workaround is to adjust your web server tracing level. For example, adding the follow settings in your web.config file would resolve the issue,

<system.webServer>
    <tracing>
     <traceFailedRequests>
        <remove path="*"/>
        <add path="*">
         <traceAreas>
            <add provider="ASP" verbosity="Verbose" />
            <!-- Note that the verbosity is set to Warning (default value is Verbose)-->
            <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Warning" />
            <add provider="ISAPI Extension" verbosity="Verbose" />
            <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,Rewrite,WebSocket" verbosity="Verbose" />
         </traceAreas>
         <failureDefinitions statusCodes="200-999" />
        </add>
     </traceFailedRequests>
    </tracing>
</system.webServer>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!