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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NishantGiri23Author Commented:
Tried..didnt work out.. infect in these link people are asking for help..?
0
Dhanasekaran SengodanCommented:
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Dhanasekaran SengodanCommented:

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

Instead, you need to use

Configuration configuration = WebConfigurationManager.OpenWebConfiguration( HttpContext.Current.Request.ApplicationPath);
0
NishantGiri23Author 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.