[英]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. 我有一个向用户发送电子邮件的应用程序,以便他们可以访问Web表单。 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. 部署应用程序后,我知道它位于inetpub / wwwroot / appName中,这将导致URL为serverip:appPort / appName。
What is the C# to get the serverip:appPort portion of the URL that I need? 获取我需要的URL的serverip:appPort部分的C#是什么?
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. 我认为server.mappath()可能可以工作,但是由于某些原因,即使有必要的引用,我也无法使用该方法。
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. 注意:我将在多个不同的服务器上部署此应用程序,实际上只是不想每次重新部署时都必须对IP进行硬编码。
Try 尝试
HttpContext.Current.Request.ServerVariables("HTTP_HOST"), this should give you the host name. HttpContext.Current.Request.ServerVariables(“ HTTP_HOST”),这应该为您提供主机名。
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 http://msdn.microsoft.com/en-us/library/system.web.httprequest.servervariables.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.