Solved

Getting the actual URL, with domain and not host name from my ASP.NET 2.0 application

Posted on 2007-03-27
2
198 Views
Last Modified: 2013-11-07
Getting the actual URL, with domain and not host name from my ASP.NET 2.0 application.

I am trying to open in IE a file (MS Word Doc) that I just uploaded through my web application on an IIS server running ASP.NET 2.0.  I am able to get a URL from the Request.Url object and this works when I am debugging locally.  However, when the application gets published to an application web server the Request.Url.AbsoluteUri returns the host name in the Url which is not accessible to a remote/browsing computer.

For example, this works on my local:
http://localhost/MyApplication/UploadedFiles/File1.doc 

This does not work when the application runs from the server:
http://serverhostname/MyApplication/UploadedFiles/File1.doc

I am able to navigate with my browser to the file and open it on the web server with a URL like:
http://www.mycompany.com/MyApplication/UploadedFiles/File1.doc 

This may be an ignorant question, but I guess that's me right now, Should I be asking for "how to get the domain?" ?
0
Comment
Question by:Bruce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
mrichmon earned 500 total points
ID: 18800949
You need to look at the server variables:

Request.ServerVariables["SERVER_NAME"]
Request.ServerVariables["URL"]
etc...
0
 
LVL 1

Author Comment

by:Bruce
ID: 18843693
mrichmon,

Thanks, but those return the same values I am already getting from Request objects other member variables.  

We finally broke down and stored the domain names in the web.config's appSettings.  We then use a Select Case on System.Environment.MachineName.ToLower().  

Select Case System.Environment.MachineName.ToLower()
    Case "dev_server"
      'Get Dev URL from web.config
      _ApplicationServerURL = ConfigurationManager.AppSettings("ServerURL_Dev")
    Case "test1_server", "test2_server", "test3_server"
      'Get Test URL from web.config
      _ApplicationServerURL = ConfigurationManager.AppSettings("ServerURL_Test")
    Case "prod1_server", "prod2_server"
      'Get Production URL from web.config
      _ApplicationServerURL = ConfigurationManager.AppSettings("ServerURL_Production")
    Case Else
      'Get Localhost URL from web.config
      _ApplicationServerURL = "http://localhost/"
End Select

<appSettings>
<add key="ServerURL_Dev" value="http://dev.dev_server.com/"/>
<add key="ServerURL_Test" value="http://test.testdomain.com"/>
<add key="ServerURL_Production" value="http://www.proddomain.com"/>            
</appSettings>

I do appreciate the effort mrichmon!  Thank you.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question