asp.net - An error occurred loading a configuration file: Failed to map the path '/' -
i error occurred loading configuration file: failed map path '/'. when try run following line path of web.config
configuration config =system.web.configuration.webconfigurationmanager.openwebconfiguration("~");
i running windows 7 , visual studio 2010 , .net framework 4.0 . know issue resolved running visual studio administrator , have run same code numerous times before doing run administrator today running administrator not resolving issue . have run same code on laptops of team mates , code works , when run code on laptop not work .
i have tried , there way can give absolute path somehow make work temporarily , can windows issue because in bad condition lately . kindly wasting lot of time
i having same problem , using same workaround of launching visual studio administrator.
finally tried tests , got this: if create filemap web.config application loads config without administrator privileges.
i have used example http://msdn.microsoft.com/en-us/library/system.web.configuration.webconfigurationmanager.openmappedwebconfiguration(v=vs.110).aspx modifications:
public static configuration getconfiguration() { if (hostingenvironment.applicationvirtualpath == "/") return webconfigurationmanager.openwebconfiguration("~/web.config"); webconfigurationfilemap filemap = createfilemap(hostingenvironment.applicationvirtualpath); // configuration object mapped virtual directory. return webconfigurationmanager.openmappedwebconfiguration(filemap, hostingenvironment.applicationvirtualpath); } private static webconfigurationfilemap createfilemap(string applicationvirtualpath) { webconfigurationfilemap filemap = new webconfigurationfilemap(); // physical directory app runs. // we'll use map virtual directories // defined next. string physdir = hostingenvironment.applicationphysicalpath; // create virtualdirectorymapping object use // root directory virtual directory // named config. // note: must assure have physical subdirectory // named config in curremt physical directory // application runs. virtualdirectorymapping vdirmap = new virtualdirectorymapping(physdir, true); // add vdirmap virtualdirectories collection // assigning virtual directory name. filemap.virtualdirectories.add(applicationvirtualpath, vdirmap); // create virtualdirectorymapping object use // default directory virtual // directories. virtualdirectorymapping vdirmapbase = new virtualdirectorymapping(physdir, true, "web.config"); // add virtual directory mapping collection. filemap.virtualdirectories.add("/", vdirmapbase); // return mapping. return filemap; }
i think not cool fix, works , can enclosed in #if debug section.
with these deducing when launch visual studio web development server having set virtual path setting "/myapplication", if has been launched administrator privileges creates mappings not create when not having privileges. hypothesis not verify.
i hope others!
Comments
Post a Comment