1

I have been getting the following error after publishing my site:

System.UnauthorizedAccessExceptionAccess to the path 'C:\inetpub\MySite\App_Data' is denied.

Turns out it's because it can't access App_Data\ASPNETDB.MDF. This is because it doesn't exist as my site doesn't use it. I checked my local machine and there is an App_Data folder with the database in but it isn't included in my build in VS. If I delete it however, it is recreated when I run the site in VS.

The site works fine after that once the error seems to clear itself but it happens every time I deploy.

There is no reference to it anywhere in code. How/Why is it getting created on application start and how do I stop it?

I am using SimpleMembership with all data stored in a SQL Server DB.

Nick Reeve
  • 1,658
  • 2
  • 22
  • 32
  • how are you initializing the simple membership connection? are you telling it to use your existing database? because it looks like its just trying to create a new database. – Matt Tabor Apr 10 '14 at 00:17
  • Show your web.config. Most likely you have a setting that tells ASP.NET you are still using the old membership provider prior to SimpleMembership. – Kevin Junghans Apr 10 '14 at 12:24
  • What part of the web.config do you want to see? There is no mention of membership anywhere in it. – Nick Reeve Apr 16 '14 at 12:10
  • Possible duplicate of [Access to the path 'c:\inetpub\wwwroot\myapp\App\_Data' is denied](http://stackoverflow.com/questions/10255790/access-to-the-path-c-inetpub-wwwroot-myapp-app-data-is-denied) – devlin carnate Mar 21 '17 at 20:27
  • I think this is answered by http://stackoverflow.com/questions/14695840/simplemembership-demands-app-data-folder – Dave M Apr 18 '17 at 11:53

2 Answers2

2

I had this problem before. when you want to publish your App, if the app_data folder was empty, it doesn't copy to the published one. so before publishing, copy a file to app_data folder, then publish your app... or you can check for exist to create inside the code:

var folder = System.Web.HttpContext.Current.Server.MapPath("~/App_Data/");
if (!Directory.Exists(folder)) 
    Directory.CreateDirectory(folder);
  • you can use this code in Global.asax => application start Method – Masoud Ghaffari Sep 17 '15 at 04:48
  • your solution solve different error about "path can not be find" but after it is created by visual studio or manually, another error appears "access is denied", IIS user has no access, but i dont know why. – Muflix Feb 10 '17 at 09:20
  • btw i just try put that code inside global.asax application_start and it does not work – Muflix Feb 10 '17 at 09:30
0

Try to go to App_Data folder property and add ASPNET user with read and write privileges

Access to the path 'c:\inetpub\wwwroot\myapp\App_Data' is denied

Community
  • 1
  • 1
Avorsa
  • 1