简体   繁体   English

ASP.NET MVC部署的应用程序服务器地址

[英]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.

相关问题 ASP.NET MVC查询未请求时已部署的应用程序服务器地址 - ASP.NET MVC query deployed Application Server Address while not in request 将 ASP.NET MVC 应用程序部署到服务器后的 Crystal 报告问题 - Crystal report Issue after deployed ASP.NET MVC application to server 如何运行已部署的ASP.NET MVC 2 Web应用程序 - How to run deployed ASP.NET MVC 2 Web Application 部署ASP.Net应用程序后出现服务器错误 - Server error after ASP.Net application deployed 在部署到IIS服务器的ASP.NET应用程序中使用Powershell - Using Powershell in an ASP.NET application deployed to an IIS server ASP.NET角色在已部署的ASP.NET MVC应用程序中不起作用 - ASP.NET Roles not working in deployed ASP.NET MVC application asp.net MVC 4 Web应用程序“ /”应用程序中的服务器错误? - asp.net MVC 4 web application Server Error in '/' Application? 部署的ASP.Net应用程序不返回数据 - Deployed ASP.Net application not returning data HostingEnvironment.QueueBackgroundWorkItem 永远不会在 azure 部署的 asp.net mvc 4.5 应用程序上执行 - HostingEnvironment.QueueBackgroundWorkItem never executes on azure deployed asp.net mvc 4.5 application 在 ASP.net Mvc 应用程序中的 IIS 中部署应用程序时,水晶报表无法加载 - Crystal report fails to load when application is deployed in IIS in ASP.net Mvc app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM