Bruce
asked on
Getting the actual URL, with domain and not host name from my ASP.NET 2.0 application
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?" ?
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?" ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.Machine
Select Case System.Environment.Machine
Case "dev_server"
'Get Dev URL from web.config
_ApplicationServerURL = ConfigurationManager.AppSe
Case "test1_server", "test2_server", "test3_server"
'Get Test URL from web.config
_ApplicationServerURL = ConfigurationManager.AppSe
Case "prod1_server", "prod2_server"
'Get Production URL from web.config
_ApplicationServerURL = ConfigurationManager.AppSe
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"
</appSettings>
I do appreciate the effort mrichmon! Thank you.