简体   繁体   中英

ASP.NET Membership, access denied to all roles

I have a problem with asp.net membership authorization, I configured my main web config like this:

<connectionStrings>
    <add name="xxx" connectionString="Data Source=; Initial Catalog=; Integrated Security=;"    providerName="System.Data.SqlClient" />
    <remove name="LocalSqlServer"/>
    <add name="LocalSqlServer"
  connectionString="Data Source=; Initial Catalog=; Integrated Security=;"
  providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
    <roleManager enabled="true" defaultProvider="MyProvider">
       <providers>
        <add name="MyProvider"
        type="System.Web.Security.SqlRoleProvider" 
        connectionStringName="Devices"
        applicationName="MembersTable" />
       </providers>
    </roleManager>

    <membership defaultProvider="MyProvider">
      <providers>
        <add name="MyProvider"
        type="System.Web.Security.SqlMembershipProvider"
        connectionStringName="" />
      </providers>          
    </membership>
    <authentication mode="Forms">
        <forms loginUrl="Denied.aspx" name=".ASPXFORMSAUTH"/>
    </authentication>
  <compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>` 

and in specified folder my config looks like

<configuration>
  <location>
    <system.web>
        <authorization>
            <allow roles="role1"/>
            <deny users="*" />
        </authorization>
    </system.web>
  </location>
</configuration>

But after login I dont get access to folder files , it returns me on Denied.aspx page I verify user with Membership.ValidateUser method and call page with Response.Redirect . Is this enough or I need a different way of requesting protected page

if (
       Membership.ValidateUser(this.txtUsername.Text, this.txtPassword.Text))
        {

                Response.Redirect("/tempUser/Role1Page.aspx");

        }
        else {
            Response.Redirect("Denied.aspx");
        }

It sounds like the user(s) aren't in the role OR roles are not quite configured properly (although it looks correct in your snippet). You can check this by viewing the Web Site configuration tool (Project Menu, ASP.Net Configuration, Security) or in code: User.IsInRole("rolename") .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM