How to get the physical path of a virtual directory?
-
I have a desktop application where user can enter a virtual directory path (like http://localhost/MySite, or http://MyMachine/MySite). The path will always be local (both virtual and physical directories located on that machine itself). I should then open "MySite" in a browser, but before that I need to fetch some settings from its web.config file. For that I should know the physical location of web.config file (which is the root of "MySite") so that I can open it. So the question is: how do I get the physical location of "MySite"? Or is there any other approach to what I want to achieve? Please remember, I have a Winform application which has nothing to do with the site "MySite", it just gets its URL through an editbox. I am new to .Net, so please forgive any stupidity.
It's better to know some of the questions than all of the answers.
Pravin. -
I have a desktop application where user can enter a virtual directory path (like http://localhost/MySite, or http://MyMachine/MySite). The path will always be local (both virtual and physical directories located on that machine itself). I should then open "MySite" in a browser, but before that I need to fetch some settings from its web.config file. For that I should know the physical location of web.config file (which is the root of "MySite") so that I can open it. So the question is: how do I get the physical location of "MySite"? Or is there any other approach to what I want to achieve? Please remember, I have a Winform application which has nothing to do with the site "MySite", it just gets its URL through an editbox. I am new to .Net, so please forgive any stupidity.
It's better to know some of the questions than all of the answers.
Pravin.I don't think you can, and this is why: your local web server somehow knows where the root of the local web is, it is like an application setting to it. Example: I am using XAMPP (=Apache) to serve a local PHP-based web site, it holds its root location deep inside a configuration file called "httpd.conf"; I am also using another web server serving an ASP.NET-based web site, it uses a different web root, stored in a different way. How could an application external to all these web servers know where to look for your web root(s)? Maybe this would work for you: organize an application setting "webroot" for your WinForm, initially "webroot" is empty. Have your app obtain its "webroot" from its setting, when getting a value, just use it; when getting no value, ask the user to locate the web root, and update the setting. That is harassing the user only once (and causing a major problem when you decide to move the web root, unless you also provide a button "Update Web Root Location" which basically empties "webroot". :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
I don't think you can, and this is why: your local web server somehow knows where the root of the local web is, it is like an application setting to it. Example: I am using XAMPP (=Apache) to serve a local PHP-based web site, it holds its root location deep inside a configuration file called "httpd.conf"; I am also using another web server serving an ASP.NET-based web site, it uses a different web root, stored in a different way. How could an application external to all these web servers know where to look for your web root(s)? Maybe this would work for you: organize an application setting "webroot" for your WinForm, initially "webroot" is empty. Have your app obtain its "webroot" from its setting, when getting a value, just use it; when getting no value, ask the user to locate the web root, and update the setting. That is harassing the user only once (and causing a major problem when you decide to move the web root, unless you also provide a button "Update Web Root Location" which basically empties "webroot". :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
Thanks for the answer, Luc. I already have this option of asking the user for webroot, storing them and later showing them in a drop-down to let him choose (or type a new one). I just wanted to remove this harassment by making my app a little more intelligent. All my users will be on Windows, using IIS 7, if that gives you any more ideas.
It's better to know some of the questions than all of the answers.
Pravin. -
Thanks for the answer, Luc. I already have this option of asking the user for webroot, storing them and later showing them in a drop-down to let him choose (or type a new one). I just wanted to remove this harassment by making my app a little more intelligent. All my users will be on Windows, using IIS 7, if that gives you any more ideas.
It's better to know some of the questions than all of the answers.
Pravin.PravinSingh wrote:
any more ideas
No, not really. A web server should obviously know, but also not reveal, where the web root is. As I explained, you don't need to ask the user each time, once is enough (unless it changes). And that once could probably be at installation time of your app. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
I have a desktop application where user can enter a virtual directory path (like http://localhost/MySite, or http://MyMachine/MySite). The path will always be local (both virtual and physical directories located on that machine itself). I should then open "MySite" in a browser, but before that I need to fetch some settings from its web.config file. For that I should know the physical location of web.config file (which is the root of "MySite") so that I can open it. So the question is: how do I get the physical location of "MySite"? Or is there any other approach to what I want to achieve? Please remember, I have a Winform application which has nothing to do with the site "MySite", it just gets its URL through an editbox. I am new to .Net, so please forgive any stupidity.
It's better to know some of the questions than all of the answers.
Pravin.Since your site will always run on IIS, you can make the site an ASP.NET app and add a web service to the site that the calling app can call to ask for the information. That's what you should be doing anyway....client apps shouldn't need direct access to that stuff.
Mark Salsbery Microsoft MVP - Visual C++ :java: