Click here to Skip to main content
15,903,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Can anyone tell me how can I get the virtual directory alias name of the website that is hosted in IIS from C# code?

Thanks in advance.
Posted
Comments
Rajesh Anuhya 25-Oct-10 7:32am    
can u elaborate the Question..,
Ankur\m/ 26-Oct-10 1:15am    
Does my answer help?

Not sure of what exactly you are talking of but you can always get the full path (absolute path) of the current page/resource you are using in the code. You will have all the things in the path - virtual directory name, resource relative path, etc. Extract the one you need.
 
Share this answer
 
Comments
bedathur_ganesh 25-Oct-10 7:51am    
While we host a website, we give the Virtual Directory Alias. I want to get this name from my C# code.
Sandeep Mewara 25-Oct-10 7:53am    
Whatever alias you give while hosting, it should be in the full URL. Isin't it there?
bedathur_ganesh 25-Oct-10 7:59am    
No, the URL will not contain the virtual directory alias name. It shows the folder name(website) that is being hosted.
Sandeep Mewara 25-Oct-10 8:04am    
I doubt that. For me the name that I give in IIS for the folder is the one I get in URL. Not the folder name.

So, if my folder name is 'MyApplication' and while hosting it I set Virtual directory as 'MyHostedApp', then when I access URL it will contain 'MyHostedApp' in it.
bedathur_ganesh 25-Oct-10 8:13am    
can you please tell me how you are using it? because in the URL I am getting the Folder Name.
Okay, I checked your discussion above.

Use this,
C#
Request.ServerVariables["PATH_INFO"];


this will give you: /alias/...

Extract the alias.

Hope this helps!
 
Share this answer
 
Comments
bedathur_ganesh 26-Oct-10 3:10am    
Thanks for the help.. But, it didnt solve my problem. It does not give the alias name.
Ankur\m/ 26-Oct-10 3:12am    
What? Can you give me the output?
try this one:

string vDirectory = "";
if (Request.ServerVariables["APPL_MD_PATH"]!="")
if (Request.ServerVariables["APPL_MD_PATH"].Remove(0, Request.ServerVariables["APPL_MD_PATH"].IndexOf("ROOT/") + 5) != "")
vDirectory = Request.ServerVariables["APPL_MD_PATH"].Remove(0, Request.ServerVariables["APPL_MD_PATH"].IndexOf("ROOT/") + 5) + "/";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900