7 Replies - 389 Views - Last Post: 19 February 2019 - 07:17 AM

#1 DarenR   User is offline

  • D.I.C Lover

Reputation: 616
  • View blog
  • Posts: 4,090
  • Joined: 12-January 10

security session isuserrole always returns false

Posted 18 February 2019 - 11:18 AM

the following line:

Session("Admin") = Roles.IsUserInRole("LIBERTY/Administrators")



i have all the roles associated under my name and no matter what i put in the role it always returns false

any thoughts?
Is This A Good Question/Topic? 0
  • +

Replies To: security session isuserrole always returns false

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15106
  • View blog
  • Posts: 60,396
  • Joined: 12-June 08

Re: security session isuserrole always returns false

Posted 18 February 2019 - 11:42 AM

Which is this? ASP.NET, Razor Pages, MVC, winform, wpf, console, etc?
Was This Post Helpful? 0
  • +
  • -

#3 DarenR   User is offline

  • D.I.C Lover

Reputation: 616
  • View blog
  • Posts: 4,090
  • Joined: 12-January 10

Re: security session isuserrole always returns false

Posted 18 February 2019 - 11:54 AM

asp.net with vb.net back end
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15106
  • View blog
  • Posts: 60,396
  • Joined: 12-June 08

Re: security session isuserrole always returns false

Posted 18 February 2019 - 12:04 PM

Like pre Razor/MVC/.NET CORE ASP.NET, right?

If it's regular ol' ASP.NET check if you are setting your session cookie as 'secure' but the page is using HTTP. (not the HTTPS).

Maybe use:
<httpCookies requireSSL="false" />
Was This Post Helpful? 0
  • +
  • -

#5 DarenR   User is offline

  • D.I.C Lover

Reputation: 616
  • View blog
  • Posts: 4,090
  • Joined: 12-January 10

Re: security session isuserrole always returns false

Posted 18 February 2019 - 12:14 PM

nah this is using 2017 vs so it has all the latest goodies
added that line and it still doesnt return anything except false

here is the full webconfig

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  
    <system.web>
      <compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
      <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider" cacheRolesInCookie="true" />
      <httpCookies requireSSL="false" />
    </system.web>
    <appSettings>
      <add key="strDBConnectionString" mydbconstring/>
      <add key="strPageSize" value="30"/>
      <add key="strCompanyCode" value="something"/>
    </appSettings>
 
 
</configuration>

This post has been edited by DarenR: 18 February 2019 - 12:13 PM

Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15106
  • View blog
  • Posts: 60,396
  • Joined: 12-June 08

Re: security session isuserrole always returns false

Posted 18 February 2019 - 12:16 PM

So just regular "old school" ASP.NET.. not Razor pages or MVC that use .NET Core?
Was This Post Helpful? 0
  • +
  • -

#7 DarenR   User is offline

  • D.I.C Lover

Reputation: 616
  • View blog
  • Posts: 4,090
  • Joined: 12-January 10

Re: security session isuserrole always returns false

Posted 18 February 2019 - 12:18 PM

correct just asp with vb on back end---- nothing fancy
Was This Post Helpful? 0
  • +
  • -

#8 DarenR   User is offline

  • D.I.C Lover

Reputation: 616
  • View blog
  • Posts: 4,090
  • Joined: 12-January 10

Re: security session isuserrole always returns false

Posted 19 February 2019 - 07:17 AM

so this is the fix:

Dim MyIdentity As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent()
        Dim MyPrincipal As System.Security.Principal.WindowsPrincipal = New System.Security.Principal.WindowsPrincipal(MyIdentity)
      
        Session("Admin") = MyPrincipal.IsInRole("Administrators")

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1