Asp.Net is looking for the web.config in the wrong

2019-07-09 01:44发布

I've got a strange issue - Up until now I've only worked on this application on a single machine. I've downloaded an asp.net web app onto a dev machine in a clients office.

When I try to run the application in debug mode through Visual Studio I get 500.19 error - typically this means a permission problem. I went through the motions of checking the permissions before I noticed the directory it was looking for the config file in.

The 'Config File' shown on the error is

\\?\C:\Users\{my-name}\Documents\{project-name}\web.config
  • however the correct location is actually

    C:\Users\admin\Documents\projects\{project-name}\web.config

Does anyone know where the location of the web config is specified? I had always assumed it could only ever be in the root directory.

3条回答
对你真心纯属浪费
2楼-- · 2019-07-09 02:27

Assuming you mean Documents\projects\{project-name}\web.config instead of Documents\projects{project-name}\web.config you're seeing the effect of Application Scopes.

In IIS, multiple entirely separate web-applications can be part of the same website by being split-up into "Application Scopes" - which usually works by specifying a prefix path followed by the Scope root (prior to IIS7 an Application Scope could be a physical or virtual directory, since IIS7 they're always virtual directories, but can still represent a physical directory).

Open IIS Manager and select the (virtual )directory that Visual Studio created for your project and right-click it in the left-side Navigation pane and choose "Convert to Application", then ASP.NET will look for the web.config file (and the bin directory, amongst others) in this folder only, rather than the website root.

Note that the website root is also considered an application scope root, hence the common error message "Exception in "/" application". If you get a YSoD in another application root you'll see "Exception in "/subFolder" application" messages.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-07-09 02:30

As it turns out the cause of this was upgrading to Visual Studio 2015.

Rather than a .suo file the new Visual Studio has a .vs folder with files specific to an instance of a project. The root directory of the development site is included in here.

I deleted the files and added .vs/* to my .gitignore file and had no more problems.

查看更多
女痞
4楼-- · 2019-07-09 02:46

In my case, the top level website in IIS had a physical path of:

C:\Users\MyUserName\Documents\My Web Sites

For some reason, this meant IIS refused to look anywhere else, even though my projects underneath had been converted to applications.

Fix for me:

  1. Go to IIS
  2. Right click on the top level website (i.e. 'Default Web Site', or the problematic website at the same level)
  3. Select 'Manage Website > Advanced Settings'
  4. Change the physical path to C:\inetpub\wwwroot
  5. Save and reload website

I could then have any path for my applications and IIS could work it out as expected.

查看更多
登录 后发表回答