简体   繁体   中英

ASP.NET MVC Deployed Application Server Address

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM