Re: problem with web.config when using roles



On Mar 3, 9:43 am, "Vincent" <vi,@sd.cv> wrote:
Hi,

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

<configuration>
<connectionStrings>
<clear/>
<add name="myconn" connectionString="Data Source=.\sqlexpress;Initial
Catalog=mydb;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>

...
<membership>
<providers>
<remove name="AspNetSqlMembershipProvider"/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="myconn" />
</providers>
</membership>
...

When i use Roles with this web.config:
------------------------------------------------------
<configuration>
<connectionStrings>
<clear/>
<add name="myconn" connectionString="Data Source=.\sqlexpress;Initial
Catalog=mydb;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
     <authorization>
      <allow roles="role1"/>
      <allow roles="role2"/>
     </authorization>
    <roleManager enabled="true">
      <providers>
      </providers>
    </roleManager>
...
<membership>
<providers>
<remove name="AspNetSqlMembershipProvider"/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="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="AspNetSqlRoleProvider"
connectionStringName="LocalSqlServer" applicationName="/" ...

Source File:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config line 149

I solved this by adding in web.config this line: <add name="LocalSqlServer"
connectionString="Data Source=.\sqlexpress;Initial Catalog=mydb;Integrated
Security=True" providerName="System.Data.SqlClient"/>

But i would like understand what happened.
Why do i have to add the second connectionString "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="AspNetSqlRoleProvider">
<providers>
<remove name="AspNetSqlRoleProvider"/>
<add connectionStringName="myconn"
applicationName="YourAppName" name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider" />
</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.

.



Relevant Pages

  • RE: security in windows app
    ... # the connectionstrings are always cofigured in the ... configuration. ... "ConfigurationManager.ConnectionStrings" static property. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: problem with web.config when using roles
    ... When the application doesn't use Roles, this configuration ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: security in windows app
    ... # the connectionstrings are always cofigured in the ... connectionstring element and read the value. ... configuration. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • problem with web.config when using roles
    ... When the application doesn't use Roles, this configuration ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: ASP.NET Configuration
    ... so that the settings you are asking about would be clearly read. ... I used ASP.NET Configuration to create a user, ...
    (microsoft.public.dotnet.framework.aspnet)