路由器端口转发和 HttpContext.Current.Request.Url
这是场景。 我们有一个路由器,可以为不同的测试站点转发请求。 例如 http://www.ourSite.com:8051 从路由器转发到 Web 服务器位于端口 80 上。测试网站是在 IIS6 (Windows Server 2003) 上运行的一个网站的虚拟目录。
我们的应用程序的一部分发送电子邮件,使用基本 URL 在应用程序中构建一些链接。 这是在应用程序启动时构建的基本 url:
siteBaseUrl = string.Format("{0}://{1}{2}",
HttpContext.Current.Request.Url.Scheme,
HttpContext.Current.Request.Url.Authority,
HttpContext.Current.Request.ApplicationPath.TrimEnd('/'));
假设我们的测试站点之一如下所示, http://www.ourSite.com:8051/client1。 我希望 siteBaseUrl 看起来像这样, http://www.ourSite.com:8051/client1,事实上它最终看起来像这样 http://www.ourSite.com/client1 (我尝试在 StackOverflow 上找到这样的问题,但没有找到。也许我没有使用正确的关键字进行搜索,或者我需要更多咖啡。对此问题的任何帮助将不胜感激。
Here's the scenario. We have a router that port forwards requests for our different test sites. For example http://www.ourSite.com:8051 forwards from the router to a web server that is on port 80. The test web sites are virtual directories of one web site running on IIS6 (Windows Server 2003).
Part of our application send out e-mails that use a base url to build some links in the application. Here's the base url being built in our on application start:
siteBaseUrl = string.Format("{0}://{1}{2}",
HttpContext.Current.Request.Url.Scheme,
HttpContext.Current.Request.Url.Authority,
HttpContext.Current.Request.ApplicationPath.TrimEnd('/'));
So let's say one of our tests site's looks like this, http://www.ourSite.com:8051/client1. I would expect siteBaseUrl to look like this, http://www.ourSite.com:8051/client1, when in fact it ends up looking like this http://www.ourSite.com/client1 (I tried finding a question like this on StackOverflow but found none. Maybe I wasn't searching with the right keywords, or I need more coffee. Any help on this matter would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HttpContext.Current.Request.Url基于从IIS请求的资源,它不代表客户端请求Url。 不过,您可以使用 HTTP 标头中的 Host 属性。
The HttpContext.Current.Request.Url is based on the resource requested from IIS, it doesn't represent the Client request Url. You can however use the Host property from the HTTP header.
如果端口号被路由器删除,您始终可以使用 JavaScript 来获取 url 并将其发送到服务器。
If the port number is getting stripped away by your router, you could always use javascript to grab the url and just send it to the server.