ASP.NET MVC的应用服务器地址 [英] ASP.NET MVC Deployed Application Server Address

查看:305
本文介绍了ASP.NET MVC的应用服务器地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有发送电子邮件给用户,以便他们可以访问Web表单的应用程序。在电子邮件存在的仅仅是这种形式的起始页面的链接。目前,我对形式的位置很难codeD的价值。一旦应用程序部署,我知道它是在的Inetpub / wwwroot文件/的appName,从而导致SERVERIP的网址:appPort /的appName

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.

什么是C#得到SERVERIP:我需要的URL的一部分appPort

What is the C# to get the serverip:appPort portion of the URL that I need?

我认为使用Server.Mappath()可能会奏效,但由于某些原因,我不能去的方法,即使我有必要引用。

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.

请注意:我会在几个不同的服务器上部署该应用程序,真的只是不想每次都必须努力code的IP我重新部署

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.

推荐答案

尝试

HttpContext.Current.Request.ServerVariables(HTTP_HOST),这应该给你的主机名。

HttpContext.Current.Request.ServerVariables("HTTP_HOST"), this should give you the host name.

这个链接会告诉你如何得到所有你(5月)需要获得端口和应用程序(如果你还没有他们)键。
http://msdn.microsoft.com/en-us/library/system.web.htt$p$pquest.servervariables.aspx

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

这篇关于ASP.NET MVC的应用服务器地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆