简体   繁体   中英

Values read from the wrong web.config in ASP.NET MVC app

I'm having a weird problem where the web.config contained within web app is not being read but it is somehow reading values from some other web.config as it is returning me an ip address and a timer value that I need set in the javascript contained in my _layoutRoot.chtml but I have no idea where else to look?

The value returned is a URL which is from my old development machine, so clearly, it must have been defined at some point but I just can't figure out where the web.config being used is.

This is one of the lines that contained in a JavaScript function in my _rootLayout.cshtml:

let apiUrl = '@ConfigurationManager.AppSettings["WebApiUrl"]';

and I've got the following namespace defined:

@using System.Configuration

This is what I've done so far:

  1. Ran iisreset, in case, something was somehow being cached.
  2. Looked for other web.config within my web app folder and sub-folders.
  3. Looked for other web.config in the root of .netpub.
  4. Looked at settings in applicationhost (just in case but was very doubtful)
  5. Check the AppSettings in IIS for my web app and they are being displayed correctly.
  6. I've checked my entire solution to make sure I hadn't stupidly hard-coded some value but it is not the case.

Is there a way in IIS to turn on logging in IIS to check which web.config is being read and where it is located?

Any suggestions as to where else I should be looking for?

Thanks.

UPDATE-1:

I was really hopeful that deleting the web app folder located in:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319

would resolve the issue as the folder was as few months old but to no avail!!

Still reading the values from god knows where!!

UPDATE-2

I found the culprit but still no idea why it's happening.

After running procmon to monitor w3wp, I noticed that it was accessing a folder where we keep our code for our web app which is located on a separate drive and guess what, in the web app folder, I opened the web.config and found the address it was using instead of the one defined in .netpub\mywebapp.

Makes no sense for various reasons:

  1. I've checked all app pools, none are pointing to the development folder where the web app code is located.

  2. I've checked all web apps, none are pointing to the development folder where the web app code is located.

I can only assume right now that at some point in time that when debugging this app in studio, instead of using IIS express, it used IIS directly from visual studio. What I can't explain right now is why IIS is still looking into this location considering point 1 & 2 and I'm 100% sure about both of these as I've checked them and re-checked them.

I'm currently searching the registry to see if .NET or IIS somehow caches information about the web app as while my current on is called MyWebApp (as an example), it is pointing to C:\.netpub\wwwroot\MyWebApp, yet the web.config is located into D:\Code\Web\MyWebApp (as an example). As I said, it makes no sense, well to me, it doesn't... for now!

The only thing I can think of right now is that somehow IIS is confused with the fact that at some point, while in .NET, I created a virtual directory with the same name as the one that's now used in c:\.netpub\wwwroot and it is somehow caching something in the registry or other.

I shouldn't have been looking for my old dev machine name but instead the web app name itself.

It transpires that there was indeed a virtual directory with the very same name as the web app I created in c:\.netpub\wwwroot but it was located, don't ask me why, in the SharePoint web app folder and was created a virtual directory!!

What a waste of time,. Hope this never happens to anyone else and if it does, hopefully this will help.

Note that I found out very quickly by opening

c:\windows\system32\.netsrv\config\applicationHost.config

and looking for my web app name, and it pointed out immediately that there was a web app and a virtual directory.

Still can't explain why the web.config from the virtual folder created in the SharePoint web app folder was being read but don't have time to investigate that part I'm afraid. Wasted too much time on this already.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM