WebConfigurationManager.OpenWebConfiguration throws Failed to map the path '/'

I am using  Configuration objConfig = WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath);
but unfortunately it throws Failed to map the path '/' error.

I also tried to provide it comeplete physical path, Virtual Path but still facing the same Issue. Even I thought to use request.ApplicationPath but failed coz Installer doesn't recognise Request object.

Could you please help me out in resolving it.

Looking forward for some reply from experts.
NishantGiri23Asked:
Who is Participating?
 
NishantGiri23Connect With a Mentor Author Commented:
Hi All,

Got the solution Below code worked fine.

public static Configuration OpenConfigFile(string configPath)
{
    var configFile = new FileInfo(configPath);
    var vdm = new VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name);
    var wcfm = new WebConfigurationFileMap();
    wcfm.VirtualDirectories.Add("/", vdm);
    return WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/");
}

Thank You.
0
 
NishantGiri23Author Commented:
Tried..didnt work out.. infect in these link people are asking for help..?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Dhanasekaran SengodanCommented:
0
 
Dhanasekaran SengodanCommented:

Configuration configuration = WebConfigurationManager.OpenWebConfiguration("\\Web.config");

Instead, you need to use

Configuration configuration = WebConfigurationManager.OpenWebConfiguration( HttpContext.Current.Request.ApplicationPath);
0
 
NishantGiri23Author Commented:
ABove I mapped the physical path with the virtual path to make it through..
0
 
NishantGiri23Author Commented:
But I still thanks all the experts who commented on it.

I also request the community to close this since I hvn't recieved the right Answer so I am not giving any points.
0
 
Dhanasekaran SengodanCommented:
For Virtual path
=============

string path = "http://" + System.Web.HttpContext.Current.Request.Url.Authority+ "/";
0
 
NishantGiri23Author Commented:
Hi hansmani:,

Thanks for sending but it didnt work because we are using it in window base application.
0
 
Dhanasekaran SengodanCommented:
First Explain clearly, r u working in windows application or web based application.  U added Zones in ASP.NET, but told now windows application.
0
 
NishantGiri23Author Commented:
Hi dhansmani:
I do apologise for your confusion, But I mentioned in my first comment that "INSTALLER doesn't recognise request object".
0
 
NishantGiri23Author Commented:
I request the community to close this since I hvn't recieved the right Answer so I am not giving any points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.