Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

problem with web.config when using roles

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vincent - 03 Mar 2008 15:43 GMT
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
Muhammad Naveed Yaseen - 03 Mar 2008 20:06 GMT
> Hi,
>
[quoted text clipped - 69 lines]
> 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.
Vincent - 03 Mar 2008 22:22 GMT
Thanks, it works now.

On Mar 3, 9:43 am, "Vincent" <vi,@sd.cv> wrote:
> Hi,
>
[quoted text clipped - 73 lines]
> 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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.