problem with web.config when using roles

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vincent

    problem with web.config when using roles

    Hi,

    When the application doesn't use Roles, this configuration (web.config)
    works:

    <configuratio n>
    <connectionStri ngs>
    <clear/>
    <add name="myconn" connectionStrin g="Data Source=.\sqlexp ress;Initial
    Catalog=mydb;In tegrated Security=True"
    providerName="S ystem.Data.SqlC lient"/>
    </connectionStrin gs>

    ....
    <membership>
    <providers>
    <remove name="AspNetSql MembershipProvi der"/>
    <add name="AspNetSql MembershipProvi der"
    type="System.We b.Security.SqlM embershipProvid er, System.Web,
    Version=2.0.0.0 , Culture=neutral , PublicKeyToken= b03f5f7f11d50a3 a"
    connectionStrin gName="myconn" />
    </providers>
    </membership>
    ....

    When i use Roles with this web.config:
    ------------------------------------------------------
    <configuratio n>
    <connectionStri ngs>
    <clear/>
    <add name="myconn" connectionStrin g="Data Source=.\sqlexp ress;Initial
    Catalog=mydb;In tegrated Security=True"
    providerName="S ystem.Data.SqlC lient"/>
    </connectionStrin gs>
    <system.web>
    <authorizatio n>
    <allow roles="role1"/>
    <allow roles="role2"/>
    </authorization>
    <roleManager enabled="true">
    <providers>
    </providers>
    </roleManager>
    ....
    <membership>
    <providers>
    <remove name="AspNetSql MembershipProvi der"/>
    <add name="AspNetSql MembershipProvi der"
    type="System.We b.Security.SqlM embershipProvid er, System.Web,
    Version=2.0.0.0 , Culture=neutral , PublicKeyToken= b03f5f7f11d50a3 a"
    connectionStrin gName="myconn" />
    </providers>
    </membership>
    ....

    I get this error: "The connection name 'LocalSqlServer ' was not found in the
    applications configuration or the connection string is empty"
    line 149: <add name="AspNetSql RoleProvider"
    connectionStrin gName="LocalSql Server" applicationName ="/" ...

    Source File:
    C:\WINDOWS\Micr osoft.NET\Frame work\v2.0.50727 \Config\machine .config line 149

    I solved this by adding in web.config this line: <add name="LocalSqlS erver"
    connectionStrin g="Data Source=.\sqlexp ress;Initial Catalog=mydb;In tegrated
    Security=True" providerName="S ystem.Data.SqlC lient"/>

    But i would like understand what happened.
    Why do i have to add the second connectionStrin g "LocalSqlServer " only when
    using Roles? Whats' the meaning of that error in machine.config?

    Thanks
    Vincent


  • Muhammad Naveed Yaseen

    #2
    Re: problem with web.config when using roles

    On Mar 3, 9:43 am, "Vincent" <vi,@sd.cvwrote :
    Hi,
    >
    When the application doesn't use Roles, this configuration (web.config)
    works:
    >
    <configuratio n>
    <connectionStri ngs>
    <clear/>
    <add name="myconn" connectionStrin g="Data Source=.\sqlexp ress;Initial
    Catalog=mydb;In tegrated Security=True"
    providerName="S ystem.Data.SqlC lient"/>
    </connectionStrin gs>
    >
    ...
    <membership>
    <providers>
    <remove name="AspNetSql MembershipProvi der"/>
    <add name="AspNetSql MembershipProvi der"
    type="System.We b.Security.SqlM embershipProvid er, System.Web,
    Version=2.0.0.0 , Culture=neutral , PublicKeyToken= b03f5f7f11d50a3 a"
    connectionStrin gName="myconn" />
    </providers>
    </membership>
    ...
    >
    When i use Roles with this web.config:
    ------------------------------------------------------
    <configuratio n>
    <connectionStri ngs>
    <clear/>
    <add name="myconn" connectionStrin g="Data Source=.\sqlexp ress;Initial
    Catalog=mydb;In tegrated Security=True"
    providerName="S ystem.Data.SqlC lient"/>
    </connectionStrin gs>
    <system.web>
         <authorizatio n>
          <allow roles="role1"/>
          <allow roles="role2"/>
         </authorization>
        <roleManager enabled="true">
          <providers>
          </providers>
        </roleManager>
    ...
    <membership>
    <providers>
    <remove name="AspNetSql MembershipProvi der"/>
    <add name="AspNetSql MembershipProvi der"
    type="System.We b.Security.SqlM embershipProvid er, System.Web,
    Version=2.0.0.0 , Culture=neutral , PublicKeyToken= b03f5f7f11d50a3 a"
    connectionStrin gName="myconn" />
    </providers>
    </membership>
    ...
    >
    I get this error: "The connection name 'LocalSqlServer ' was not found in the
    applications configuration or the connection string is empty"
    line 149: <add name="AspNetSql RoleProvider"
    connectionStrin gName="LocalSql Server" applicationName ="/" ...
    >
    Source File:
    C:\WINDOWS\Micr osoft.NET\Frame work\v2.0.50727 \Config\machine .config line 149
    >
    I solved this by adding in web.config this line: <add name="LocalSqlS erver"
    connectionStrin g="Data Source=.\sqlexp ress;Initial Catalog=mydb;In tegrated
    Security=True" providerName="S ystem.Data.SqlC lient"/>
    >
    But i would like understand what happened.
    Why do i have to add the second connectionStrin g "LocalSqlServer " only when
    using Roles? Whats' the meaning of that error in machine.config?
    >
    Thanks
    Vincent
    Membership providers do not deal with roles. Add a role provider node
    at sibling level of membership node. That would override
    machin.config's default role provider settings.
    .
    <roleManager enabled="true" defaultProvider ="AspNetSqlRole Provider">
    <providers>
    <remove name="AspNetSql RoleProvider"/>
    <add connectionStrin gName="myconn"
    applicationName ="YourAppNam e" name="AspNetSql RoleProvider"
    type="System.We b.Security.SqlR oleProvider" />
    </providers>
    </roleManager>

    By the way, it appears you might be missing applicationName attribute
    in membership provide. It is usually good practice to have it (but
    doing it too late in project would make previously defined data
    inaccessible). If you don't want to have custom applicationName in
    membership provider, skip it from role provider too.

    Comment

    • Vincent

      #3
      Re: problem with web.config when using roles

      Thanks, it works now.


      "Muhammad Naveed Yaseen" <mnyaseen@gmail .comschreef in bericht
      news:c9887dcb-d7d9-4304-a69d-5c7bb8849bc8@e2 5g2000prg.googl egroups.com...
      On Mar 3, 9:43 am, "Vincent" <vi,@sd.cvwrote :
      Hi,
      >
      When the application doesn't use Roles, this configuration (web.config)
      works:
      >
      <configuratio n>
      <connectionStri ngs>
      <clear/>
      <add name="myconn" connectionStrin g="Data Source=.\sqlexp ress;Initial
      Catalog=mydb;In tegrated Security=True"
      providerName="S ystem.Data.SqlC lient"/>
      </connectionStrin gs>
      >
      ...
      <membership>
      <providers>
      <remove name="AspNetSql MembershipProvi der"/>
      <add name="AspNetSql MembershipProvi der"
      type="System.We b.Security.SqlM embershipProvid er, System.Web,
      Version=2.0.0.0 , Culture=neutral , PublicKeyToken= b03f5f7f11d50a3 a"
      connectionStrin gName="myconn" />
      </providers>
      </membership>
      ...
      >
      When i use Roles with this web.config:
      ------------------------------------------------------
      <configuratio n>
      <connectionStri ngs>
      <clear/>
      <add name="myconn" connectionStrin g="Data Source=.\sqlexp ress;Initial
      Catalog=mydb;In tegrated Security=True"
      providerName="S ystem.Data.SqlC lient"/>
      </connectionStrin gs>
      <system.web>
      <authorizatio n>
      <allow roles="role1"/>
      <allow roles="role2"/>
      </authorization>
      <roleManager enabled="true">
      <providers>
      </providers>
      </roleManager>
      ...
      <membership>
      <providers>
      <remove name="AspNetSql MembershipProvi der"/>
      <add name="AspNetSql MembershipProvi der"
      type="System.We b.Security.SqlM embershipProvid er, System.Web,
      Version=2.0.0.0 , Culture=neutral , PublicKeyToken= b03f5f7f11d50a3 a"
      connectionStrin gName="myconn" />
      </providers>
      </membership>
      ...
      >
      I get this error: "The connection name 'LocalSqlServer ' was not found in
      the
      applications configuration or the connection string is empty"
      line 149: <add name="AspNetSql RoleProvider"
      connectionStrin gName="LocalSql Server" applicationName ="/" ...
      >
      Source File:
      C:\WINDOWS\Micr osoft.NET\Frame work\v2.0.50727 \Config\machine .config line
      149
      >
      I solved this by adding in web.config this line: <add
      name="LocalSqlS erver"
      connectionStrin g="Data Source=.\sqlexp ress;Initial Catalog=mydb;In tegrated
      Security=True" providerName="S ystem.Data.SqlC lient"/>
      >
      But i would like understand what happened.
      Why do i have to add the second connectionStrin g "LocalSqlServer " only
      when
      using Roles? Whats' the meaning of that error in machine.config?
      >
      Thanks
      Vincent
      Membership providers do not deal with roles. Add a role provider node
      at sibling level of membership node. That would override
      machin.config's default role provider settings.
      ..
      <roleManager enabled="true" defaultProvider ="AspNetSqlRole Provider">
      <providers>
      <remove name="AspNetSql RoleProvider"/>
      <add connectionStrin gName="myconn"
      applicationName ="YourAppNam e" name="AspNetSql RoleProvider"
      type="System.We b.Security.SqlR oleProvider" />
      </providers>
      </roleManager>

      By the way, it appears you might be missing applicationName attribute
      in membership provide. It is usually good practice to have it (but
      doing it too late in project would make previously defined data
      inaccessible). If you don't want to have custom applicationName in
      membership provider, skip it from role provider too.


      Comment

      Working...