473,396 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem with web.config when using roles

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\Conf ig\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
Mar 3 '08 #1
2 7035
On Mar 3, 9:43*am, "Vincent" <vi,@sd.cvwrote:
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\Conf ig\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.

Mar 3 '08 #2
Thanks, it works now.
"Muhammad Naveed Yaseen" <mn******@gmail.comschreef in bericht
news:c9**********************************@e25g2000 prg.googlegroups.com...
On Mar 3, 9:43 am, "Vincent" <vi,@sd.cvwrote:
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\Conf ig\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.
Mar 3 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: babylon | last post by:
i have a .Net dll and there are codes to access the AppSettings inside the dll However, I would like to use the dll from a C++ program by wrapping the .Net dll as a COM So..how could I...
1
by: Rhy Mednick | last post by:
I'm creating a custom control (inherited from UserControl) that is displayed by other controls on the form. I would like for the control to disappear when the user clicks outside my control the...
13
by: Bev in TX | last post by:
We are using Visual Studio .NET 2003. When using that compiler, the following example code goes into an endless loop in the "while" loop when the /Og optimization option is used: #include...
0
by: Eugene | last post by:
Hi, I have a template in html and want to use web matrix to create a form. I am able to open the file and use the web controls after changing the file extension to aspx. But after saving the...
10
by: Anthony Williams | last post by:
Hi gang, This one looks like a bug :o( As you may or may not know, setting session management in web.config to use cookieless sessions causes the ASP.NET runtime to munge a session ID into...
2
by: Dan | last post by:
hi ng, is there a way to set a page the user gets redirected when using windows authentification (and the user gets authentificated by active directory) and authorization failed?) i have tried...
2
by: thechaosengine | last post by:
Hi eveyone, If anyone could advise on the following I would be truly greatful: I have a fairly standard set up. An IIS 5.1 website set up with anonymous access allowed in all areas of the site...
0
by: jeremy | last post by:
Had a tough time figuring this one out and couldn't find a good solution, so I thought I would post this and hopefully it will help someone out. When using DataBind to dynamically bind a list to...
1
by: Piotrekk | last post by:
Hi I have a strange problem. Here is some input data before I describe the problem. 1. RemoteClass (Mathematica) is compiled into dll and put to GAC 2. Server remoting configuration is done by...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.