Josh
Josh

Reputation: 2006

How do I not use the App_Data folder in an ASP MVC4 application?

Everything works fine locally, but when I publish, I get the error below. I am using forms authentication, but I define my own connection string to a non-sqlexpress database. I don't understand why my application would need access to create a database (or anything else) in the App_Data folder, because my database is not/will not be there. Any help is appreciated.

Connection String:

<connectionStrings>
    <add name="DataContext" providerName="System.Data.SqlClient" connectionString="Data Source=localhost;Initial Catalog={my db};Integrated Security=SSPI;MultipleActiveResultSets=True" />
</connectionStrings>

Error:

Access denied creating App_Data subdirectory

Description: For security reasons, the identity 'IIS APPPOOL\ASP.NET v4.0' (under which this web application is running), does not have permissions to create the App_Data subdirectory within the application root directory. ASP.NET stores the Microsoft SQL Express Database file used for services such as Membership and Profile in the App_Data subdirectory of your application.

Edit: It tells me how to fix the error by adding the App_Data folder and providing the correct permissions, but I don't understand why I need this folder at all, and if I can avoid changing permissions, I'd like to.

Upvotes: 1

Views: 1794

Answers (3)

Rob
Rob

Reputation: 1

*<membership>
    <providers>
        <clear />       
    </providers>
</membership>
<roleManager enabled="false">
    <providers>
        <clear />       
    </providers>
</roleManager>
<profile>
    <providers>
        <clear />       
    </providers>
</profile>*

Upvotes: 0

Josh
Josh

Reputation: 2006

I think I finally figured out how to stop ASP from trying to create the ASPNETDB.MDF database in the App_Data folder automatically. What I found worked combined two existing stackoverflow answers:

Disable SQL Membership Provider (ASP.Net Forms Authentication)

It turns out that, on the production machine, the SQL membership provider was defined in machine.config. I don't think the ops team changed anything from the default Windows 2008 install, so that's probably generally the case for that platform.

To remove references to any SQL providers defined at a higher level include the following in your web.config

<membership>
    <providers>
        <clear />       
    </providers>
</membership>
<roleManager enabled="false">
    <providers>
        <clear />       
    </providers>
</roleManager>
<profile>
    <providers>
        <clear />       
    </providers>
</profile>

AspNet Role provider kicking in and it shouldn't be

To disable 'SimpleMembership' you can add app setting enableSimpleMembership with value="false" (web.config). This will prevent webmatrix from reconfiguring RoleManager.

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <appSettings>
        <add key="enableSimpleMembership" value="false" />
    </appSettings>
</configuration>

Upvotes: 1

Stephen
Stephen

Reputation: 2047

Check if the 'connectionStringName' property of the 'membership' node in your web.config is set to your connectionstring, like this:

<membership defaultProvider="DefaultMembershipProvider">
  <providers>
    <add name="DefaultMembershipProvider" 
         type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
         connectionStringName="DataContext"
         enablePasswordRetrieval="false" 
         enablePasswordReset="true" 
         requiresQuestionAndAnswer="false" 
         requiresUniqueEmail="false" 
         maxInvalidPasswordAttempts="5" 
         minRequiredPasswordLength="6" 
         minRequiredNonalphanumericCharacters="0" 
         passwordAttemptWindow="10" 
         applicationName="/" />
  </providers>
</membership>

Upvotes: 0

Related Questions