Reputation: 673
I have an application that sends an email to a user so that they may access a web form. In the email there is just a link to the start page of this form. Currently, I have the value for the form location hardcoded. Once the app is deployed I know it is in inetpub/wwwroot/appName, which results in a URL of serverip:appPort/appName.
What is the C# to get the serverip:appPort portion of the URL that I need?
I think that server.mappath() might work, but for some reason I can't get to the method even though I have the necessary references.
Note: I will be deploying this application on several different servers and really just don't want to have to hardcode the IP every time I re-deploy.
Upvotes: 1
Views: 1277
Reputation: 679
Try
HttpContext.Current.Request.ServerVariables("HTTP_HOST"), this should give you the host name.
this link will show you how to get all the keys you (may) need to get the port and application (if you don't already have them). http://msdn.microsoft.com/en-us/library/system.web.httprequest.servervariables.aspx
Upvotes: 3