Access provider and web.config issue

Discussion in 'ASP.NET / ASP.NET Core' started by Mathetes, Feb 10, 2009.

  1. Hi group,
    I've created a simple web application to be published in DiscountAsp WITHOUT having an SQL Server addon: my customers plan it for the future, but at this time we just need some testing and we must stick with Access, as we use it only for authentication purposes. So I created a web application (with VS2008 and DotNet 3.5, IIS 7 server) using an Access provider as described in http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=404.
    The application works fine locally and I can define users roles thus restricting access to some folders. Anyway, when I publish the application in the server and try to access its homepage I get the following error from machine.config:

    ===========================
    Configuration Error
    Parser Error Message: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.

    Source Error:
    Line 158: <roleManager>
    Line 159: <providers>
    Line 160: <add name='AspNetSqlRoleProvider' connectionStringName='LocalSqlServer' applicationName='/' type='System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'/>
    Line 161: <add name='AspNetWindowsTokenRoleProvider' applicationName='/' type='System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'/>
    Line 162: </providers>

    Source File: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config Line: 160
    ===========================

    It looks like my web application is searching for the default SQL Server provider for authentication, even if my web.config explicitly states I'm using an alternate provider, as shown below, and I've ensured to add a <clear/> statement before adding my own provider. Could anyone give a hint? The relevant section of my application web.config follows.
    Thanks!

    ===========================WEB.CONFIG===
    <connectionStrings>
    <add name='AccessFileName' connectionString='~/App_Data/ASPNetDB.mdb' providerName='System.Data.OleDb'/>
    </connectionStrings>

    <system.web>
    <membership defaultProvider='AccessMembershipProvider'>
    <providers>
    <clear/>
    <add name='AccessMembershipProvider'
    type='Samples.AccessProviders.AccessMembershipProvider, AccessProvider'
    connectionStringName='AccessFileName'
    enablePasswordRetrieval='false'
    enablePasswordReset='false'
    requiresUniqueEmail='false'
    requiresQuestionAndAnswer='false'
    minRequiredPasswordLength='1'
    minRequiredNonalphanumericCharacters='0'
    applicationName='Test'
    hashAlgorithmType='SHA1'
    passwordFormat='Hashed'/>
    </providers>
    </membership>
    <roleManager enabled='true' cacheRolesInCookie='true' defaultProvider='AccessRoleProvider'>
    <providers>
    <add connectionStringName='AccessFileName' applicationName='SampleSite'
    name='AccessRoleProvider' type='Samples.AccessProviders.AccessRoleProvider, AccessProvider' />
    </providers>
    </roleManager>
    <profile enabled='true' defaultProvider='AccessProfileProvider'>
    <providers>
    <add name='AccessProfileProvider' type='Samples.AccessProviders.AccessProfileProvider, AccessProvider' connectionStringName='AccessFileName' applicationName='SampleSite' description='Stores and retrieves profile data from an AccessProvider database.'/>
    </providers>
    <properties>
    <add name='FriendlyName' type='string' allowAnonymous='true' serializeAs='String'/>
    <add name='Height' type='int' allowAnonymous='true' serializeAs='String'/>
    <add name='Weight' type='int' allowAnonymous='true' serializeAs='Xml'/>
    </properties>
    </profile>
    <anonymousIdentification enabled='true' cookieName='.ASPXANONYMOUS' cookieTimeout='100000' cookiePath='/' cookieRequireSSL='false' cookieSlidingExpiration='true' cookieProtection='None' domain=''/>
    <webParts>
    <personalization defaultProvider='AccessPersonalizationProvider'>
    <providers>
    <add name='AccessPersonalizationProvider' type='Samples.AccessProviders.AccessPersonalizationProvider, AccessProvider' connectionStringName='AccessFileName' applicationName='SampleSite'/>
    </providers>
    </personalization>
    </webParts>
    ===========================
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    asp.net does that automatically. you can solve the problem by simply adding a LocalSQLServer connection string.

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. Thank you for your reply, I knew about the default SQL Server-based default provider but my account had not an SQL Server addon. Now as I've written in another post I've added one and just set the connection string like:

    <connectionStrings>
    <remove name='LocalSqlServer' />
    <add name='LocalSqlServer'
    connectionString='Data Source=tcp:...;Initial Catalog=...;User ID=...;Password=...'
    providerName='System.Data.SqlClient' />
    </connectionStrings>

    Anyway the application locally uses the specified remote provider and works fine: I am redirected to the login page when entering restricted areas, I can use VS2008 asp.net configuration to configure users, roles, rules, and the like; but when I publish the application remotely it works but the login page never comes out and any anonymous user is allowed to browse the entire site. Could you suggest any explanation for this behaviour?
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    well... if you are using the membership provider, you'll need to activate SQL addon.

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  5. I finally found the problem: for some reason the PUBLISH command of VS2008 does not copy my web.config files in the restricted folders to the FTP space. The file was effectively missing from the remote site, and thus no restriction was in place. This is odd, but once you know it it's trivial...
    Thanks anyway!
     
  6. Thank you again, but I'm not sure to understand what you mean with 'activating': I can access the SQL server 2008 section from my account (I get the pie chart with info about space, connection string etc), I can connect to the database using SQL Server Management from my PC and execute queries on the database, view the users defined with VS2008 etc. It just does not work when the application is launched remotely. If I launch it locally I have no problem and the Login appears when expected, using data from the SQL Server remote provider. This is odd as there must be some difference between the local and remote machine I cannot think of, and the same code (which is just the 'standard' way of doing such things in ASP.NET) works with no problem for some other sites hosted in different providers. Tech support suggested me to ask the forum... Any idea?
     

Share This Page