problem with web.config when using roles

V

Vincent

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
 
M

Muhammad Naveed Yaseen

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.
 
V

Vincent

Thanks, it works now.


"Muhammad Naveed Yaseen" <[email protected]> schreef in bericht
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top