We help IT Professionals succeed at work.

ASP.Net C# error in role manager

homeshopper
homeshopper asked
on
870 Views
Last Modified: 2012-05-05
I am running a windows 2003 Virtual Server with SQL 2000 Server.
When I login to a management file with <roleManager enabled="true" /> in the main config file I get the following error:
Source Error:
Line 125:    <roleManager>
Line 126:      <providers>
Line 127:        <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Line 128:        <add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Line 129:      </providers>
Source File: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config    Line: 127

If I set <roleManager enabled="false" /> I then get an error as follows:
Source Error:
Line 115:    <membership>
Line 116:      <providers>
Line 117:        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
Line 118:      </providers>
Line 119:    </membership>
Source File: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config    Line: 117
My complete config file is as follows:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <appSettings configSource="appSettings.config">
  </appSettings>
  <connectionStrings>
    <!--
<add name="store"
connectionString="
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|STOREDB.mdf;User Instance=true    
"/>

<add name="store"
connectionString="
data source=s15235820;initial catalog=STOREDB;persist security info=False;user id=sa;password=yYCmgWVn;packet size=4096
"
providerName="System.Data.SqlClient"/>
-->
    <add name="store"
         connectionString="data source=s15235820;
         initial catalog=STOREDB;
         persist security info=False;
         user id=sa;password=yYCmgWVn;
         packet size=4096"
          providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <customErrors mode="Off"/>
    <anonymousIdentification enabled="true"/>
    <compilation debug="true" />
<!--
 <roleManager enabled="true" />
-->
    <roleManager enabled="true" />
    <authentication mode="Forms" />
    <pages theme="StoreTheme">
      <controls>
        <add tagPrefix="custom" namespace="AspNetUnleashed"/>
        <add tagPrefix="user" tagName="ProductTemplate" src="~/Templates/ProductTemplate.ascx" />
        <add tagPrefix="user" tagName="CategoryTemplate" src="~/Templates/CategoryTemplate.ascx" />
        <add tagPrefix="user" tagName="FeaturedProductView" src="~/UserControls/FeaturedProductView.ascx" />
        <add tagPrefix="user" tagName="ProductView" src="~/UserControls/ProductView.ascx" />
        <add tagPrefix="user" tagName="CategoryView" src="~/UserControls/CategoryView.ascx" />
      </controls>
    </pages>
    <siteMap defaultProvider="MySiteMapProvider">
      <providers>
        <add
          name="MySiteMapProvider"
          type="System.Web.XmlSiteMapProvider"
          securityTrimmingEnabled="true"
          siteMapFile="~/Web.sitemap" />
        <add
          name="CategorySiteMapProvider"
          type="AspNetUnleashed.CategorySiteMapProvider"
          connectionStringName="Store"
          navigateUrl="~/Products.aspx"/>
      </providers>
    </siteMap>
    <membership defaultProvider="MyMembershipProvider">
      <providers>
        <add
          name="MyMembershipProvider"
          type="System.Web.Security.SqlMembershipProvider"
          connectionStringName="LocalSqlServer"
          enablePasswordRetrieval="false"
          requiresQuestionAndAnswer="true"
          requiresUniqueEmail="false"
          passwordFormat="Encrypted"
          maxInvalidPasswordAttempts="10"
          minRequiredPasswordLength="3"
          minRequiredNonalphanumericCharacters="0"
          passwordAttemptWindow="10"
          passwordStrengthRegularExpression="" />
      </providers>
    </membership>
    <caching>
      <sqlCacheDependency enabled="true" pollTime="15000">
        <databases>
          <add name="StoreDB" connectionStringName="Store"/>
        </databases>
      </sqlCacheDependency>
    </caching>
    <machineKey
      decryption="AES"
      validation="SHA1"
      decryptionKey="306C1FA852AB3B0115150DD8BA30821CDFD125538A0C606DACA53DBB3C3E0AD2"
      validationKey="61A8E04A146AFFAB81B6AD19654F99EA7370807F18F5002725DAB98B8EFD19C711337E26948E26D1D174B159973EA0BE8CC9CAA6AAF513BF84E44B2247792265" />
  </system.web>
  <system.net>
    <mailSettings>
      <smtp
        deliveryMethod="PickupDirectoryFromIis"
        from="ian@rite.net" />
    </mailSettings>
  </system.net>
</configuration>
The code runs fine on my home computer, but not on the Private Virtual Server.
Thanks in advance.

<roleManager enabled="false" />
Source Error: 
Line 115:    <membership>
Line 116:      <providers>
Line 117:        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
Line 118:      </providers>
Line 119:    </membership>
Source File: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config    Line: 117 
 
<roleManager enabled="true" />
Source Error: 
Line 125:    <roleManager>
Line 126:      <providers>
Line 127:        <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Line 128:        <add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Line 129:      </providers>
Source File: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config    Line: 127

Open in new window

Comment
Watch Question

Author

Commented:
If I run the following code to list Users I get the same error with the follwing web.config file
in my manage folder:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>List Users</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView
        id="grdUsers"
        DataSourceID="srcUsers"
        Runat="server" />
   
    <asp:ObjectDataSource
        id="srcUsers"
        TypeName="System.Web.Security.Membership"
        SelectMethod="GetAllUsers"
        Runat="server" />
    </div>
    <div>
    <a href"../Default.aspx">Return</a>
    </div>
    </form>
</body>
</html>

<?xml version="1.0"?>
<configuration>
    <system.web>
      <authorization>
        <allow roles="StoreAdmins"/>
        <deny users="*"/>
      </authorization>
    </system.web>
</configuration>

Author

Commented:
I also have a file called UsersOnline in the App_Code folder as follows:
using System;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace myControls
{

    /// <summary>
    /// Displays Number of Users Online
    /// </summary>
    public class UsersOnline : WebControl
    {
        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.Write(Membership.GetNumberOfUsersOnline());
        }

    }
}

Author

Commented:
I have added a global.asax as below and altered the web.config file to:
<membership defaultProvider="MyMembershipProvider">
      <providers>
        <add
          name="MyMembershipProvider"
          type="System.Web.Security.SqlMembershipProvider"
          connectionStringName="store"
          enablePasswordRetrieval="false"
          requiresQuestionAndAnswer="true"
          requiresUniqueEmail="false"
          passwordFormat="Encrypted"
          maxInvalidPasswordAttempts="10"
          minRequiredPasswordLength="3"
          minRequiredNonalphanumericCharacters="0"
          passwordAttemptWindow="10"
          passwordStrengthRegularExpression="" />
      </providers>
    </membership>
Still getting an error in the machine.config file as below:
Source Error:
Line 125:    <roleManager>
Line 126:      <providers>
Line 127:        <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Line 128:        <add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Line 129:      </providers>
Source File: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config    Line: 127


<script runat="server">
    /// <summary>
    /// When the application starts, add the Admin user and 
    /// StoreAdmins role.
    /// </summary>
    void Application_Start(object sender, EventArgs e) 
    {
        MembershipCreateStatus status = new MembershipCreateStatus();
        if (!Roles.RoleExists("StoreAdmins"))
            Roles.CreateRole("StoreAdmins");
        if (Membership.GetUser("Admin") == null)
            Membership.CreateUser("Admin", "secret", "", "dog", "rover", true, out status);
        if (!Roles.IsUserInRole("Admin", "StoreAdmins"))
            Roles.AddUserToRole("Admin", "StoreAdmins");
            
        SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(SiteMap_SiteMapResolve);
    }
    /// <summary>
    /// Return correct SiteMapNode for Category when visiting the
    /// ProductDetails.aspx page.
    /// </summary>
    SiteMapNode SiteMap_SiteMapResolve(object sender, SiteMapResolveEventArgs e)
    {
        if (!String.IsNullOrEmpty(e.Context.Request.QueryString["pid"]))
        {
            int productId = Int32.Parse(e.Context.Request.QueryString["pid"]);
            int categoryId = Category.SelectIdByProductId(productId);
            SiteMapNode node = e.Provider.FindSiteMapNodeFromKey(categoryId.ToString());
            return node;
        }
        return SiteMap.CurrentNode;
    }
    /// <summary>
    /// When an anonymous user logins, modify shopping cart items to
    /// reflect authenticated user name.
    /// </summary>
    public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
    {
        ShoppingCart.AuthenticateCart(args.AnonymousID, User.Identity.Name);
        AnonymousIdentificationModule.ClearAnonymousIdentifier();
    }   
</script>

Open in new window

Author

Commented:
I think I may need to instal a database called ASPNET.MDF
that handles roles and memberships etc
by running installcommon.sql and installmembership.sql
from the \windows\microsoft.net\framework\v2.0.50727\
One problem is that I can not get sqlexpress to install on the server.

Author

Commented:
I have created the ASPNET.mdf to store users, membership roles etc.
But still get the same error. Experts please advise.
Source Error: 
Line 115:    <membership>
Line 116:      <providers>
Line 117:        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
Line 118:      </providers>
Line 119:    </membership>
Source File: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config    Line: 117 

Open in new window

Author

Commented:
when i reenable role manager the following error appears:
Source Error: 
Line 125:    <roleManager>
Line 126:      <providers>
Line 127:        <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Line 128:        <add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Line 129:      </providers>
Source File: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config    Line: 127 

Open in new window

Author

Commented:
Fixed it, found the solution by deleting ASPNETDB, web.config & global.asax
reconstructed ASPNETDB by running the following files:
installcommon.sql, installMembership.sql, installRoles.sql, installWebEventSqlProvider
reconstructed the web.config as attached code snippet
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <connectionStrings>
    <!--
<add name="store"
connectionString="
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|STOREDB.mdf;User Instance=true     
"/>
 
<add name="store"
connectionString="
data source=s15235820;initial catalog=STOREDB;persist security info=False;user id=sa;password=yYCmgWVn;packet size=4096
"
providerName="System.Data.SqlClient"/>
Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Trusted_Connection=Yes;
Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
<add name="LocalSqlServer"
         connectionString="data source=fuertemon;
         Initial Catalog=ASPNETDB;
         persist security info=False;
         user id=sa;password=yYCmgWVn"/>
<add name="LocalSqlServer"
         connectionString="data source=s15235820;
         Initial Catalog=ASPNET.MDF;
         Integrated Security=True"/>
<add name="AZConnection" 
connectionString="msxml://~/App_Data/WebRoles.xml"/>
-->
<add name="store"
 connectionString="data source=s15235820;
 initial catalog=STOREDB;
 persist security info=False;
 user id=sa;password=yYCmgWVn;packet size=4096"
 providerName="System.Data.SqlClient"/>
    <add name="LocalSqlServer"
         connectionString="data source=s15235820;
         Initial Catalog=ASPNETDB;
         persist security info=False;
         user id=sa;password=yYCmgWVn"/>
  </connectionStrings>
  <system.web>
      <anonymousIdentification enabled="true"/>
      <compilation debug="true" />
      <roleManager enabled="true" />
      <authentication mode="Forms" />
      <pages theme="StoreTheme">
        
        <controls>
          <add tagPrefix="custom" namespace="AspNetUnleashed"/>
          <add tagPrefix="user" tagName="ProductTemplate" src="~/Templates/ProductTemplate.ascx" />
          <add tagPrefix="user" tagName="CategoryTemplate" src="~/Templates/CategoryTemplate.ascx" />
          <add tagPrefix="user" tagName="FeaturedProductView" src="~/UserControls/FeaturedProductView.ascx" />
          <add tagPrefix="user" tagName="ProductView" src="~/UserControls/ProductView.ascx" />
          <add tagPrefix="user" tagName="CategoryView" src="~/UserControls/CategoryView.ascx" />
        </controls>
      </pages>
 
      <siteMap defaultProvider="MySiteMapProvider">
        <providers>
          <add
            name="MySiteMapProvider"
            type="System.Web.XmlSiteMapProvider"
            securityTrimmingEnabled="true"
            siteMapFile="~/Web.sitemap" />
          <add
            name="CategorySiteMapProvider"
            type="AspNetUnleashed.CategorySiteMapProvider"
            connectionStringName="Store"
            navigateUrl="~/Products.aspx"/>
        </providers>
      </siteMap>
 
      <membership defaultProvider="MyMembershipProvider">
        <providers>
          <add
            name="MyMembershipProvider"
            type="System.Web.Security.SqlMembershipProvider"
            connectionStringName="LocalSqlServer"
            enablePasswordRetrieval="false"
            requiresQuestionAndAnswer="true"
            requiresUniqueEmail="false"
            passwordFormat="Encrypted"
            maxInvalidPasswordAttempts="10"
            minRequiredPasswordLength="3"
            minRequiredNonalphanumericCharacters="0"
            passwordAttemptWindow="10"
            passwordStrengthRegularExpression="" />
        </providers>
      </membership>
 
      <caching>
        <sqlCacheDependency enabled="true" pollTime="15000">
          <databases>
            <add name="StoreDB" connectionStringName="Store"/>
          </databases>
        </sqlCacheDependency>
      </caching>
      
      <machineKey
        decryption="AES"
        validation="SHA1"
        decryptionKey="306C1FA852AB3B0115150DD8BA30821CDFD125538A0C606DACA53DBB3C3E0AD2"
        validationKey="61A8E04A146AFFAB81B6AD19654F99EA7370807F18F5002725DAB98B8EFD19C711337E26948E26D1D174B159973EA0BE8CC9CAA6AAF513BF84E44B2247792265" />
 
  </system.web>
  <system.net>
    <mailSettings>
      <smtp
        deliveryMethod="PickupDirectoryFromIis"
        from="ian@rite.net" />
    </mailSettings>
  </system.net>
</configuration>

Open in new window

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.