获取原始地址,而不非标准端口(C#) [英] Get original url without non-standard port (C#)
问题描述
第一个问题!
环保
MVC,C#,AppHarbor。
MVC, C#, AppHarbor.
问题
我打电话是一个OpenID提供商,并基于域的绝对回调URL。
I am calling an openid provider, and generating an absolute callback url based on the domain.
在我的本地机器,这工作正常,如果我打的http://本地主机:12345 /登录
On my local machine, this works fine if I hit http://localhost:12345/login
Request.Url; //gives me `http://localhost:12345/callback`
不过,AppHarbor在那里我部署,因为他们使用的是非标准的端口,即使我打它在的 http://sub.example.com/login
Request.Url; //gives me http://sub.example.com:15232/callback
和这个螺丝了我的回调,因为端口号在原来的源地址或文件不!
And this screws up my callback, because the port number wasn't in the original source url!
我试过
- Request.Url
- Request.Url.OriginalString
- Request.RawUrl
所有给我 http://sub.example.com:15232/callback
另外要澄清,这不是一个领域的问题,我从DotNetOpenAuth是
Also to clear up that this isn't a Realm issue, the error message I am getting from DotNetOpenAuth is
'http://sub.example.com:14107/accounts/openidcallback' not under realm 'http://*.example.com/'.
我不认为我已经塞满了呢?
I don't think I've stuffed that up?
现在,我就要考虑象
- preprocessor命令(#IF DEBUG然后把PORT)
- 字符串替换(Request.URL.Contains(本地主机))
所有这些,都没有100%的解决方案,但我生病了思索什么可能是我缺少一个简单的属性的。我也看过<一个href=\"http://stackoverflow.com/questions/40680/how-do-i-get-the-full-url-of-the-page-i-am-on-in-c\">this但似乎并不有一个公认的答案(和更多的路径,而不是权力)。所以我把它向你们。
All of these are not 100% solutions, but I'm sick of mulling over what could be a simple property that I am missing. I have also read this but that doesn't seem to have an accepted answer (and is more about the path rather than the authority). So I'm putting it towards you guys.
摘要
所以,如果我有的http://本地主机:12345 /登录
,我需要获得的http://本地主机:12345 /回调
从请求上下文。
So if I had http://localhost:12345/login
, I need to get http://localhost:12345/callback
from the Request context.
如果我有 http://sub.example.com/login ,我应该得到 http://sub.example.com/callback ,不管是哪个端口的它是。
And if I had "http://sub.example.com/login", I should get "http://sub.example.com/callback", regardless of what port it is on.
谢谢! (睡眠时间,将回答早晨任何问题)
Thanks! (Sleep time, will answer any questions in the morning)
推荐答案
这是在负载均衡设置像AppHarbor的一个共同的问题 - 我们提供了一个<一个href=\"http://support.appharbor.com/kb/getting-started/workaround-for-generating-absolute-urls-without-port-number\">example解决方法。
This is a common problem in load balanced setups like AppHarbor's - we've provided an example workaround.
更新:对于许多ASP.NET应用程序更理想的解决方案可能是将 ASPNET:UseHostHeaderForRequestUrl
appSetting到真正
。我们(AppHarbor)见过几个顾客体验使用它的问题与他们的应用程序WCF,这就是为什么我们还没有启用默认情况下它和STIL建议对于这种情况,上述溶液。您可以使用AppHarbor的配置变量部署时注入AppSettings的配置。更多信息可以在这篇文章。
Update: A more desirable solution for many ASP.NET applications may be to set the aspnet:UseHostHeaderForRequestUrl
appSetting to true
. We (AppHarbor) have seen several customers experience issues using it with their WCF apps, which is why we haven't enabled it by default and stil recommend the above solution for those situations. You can configure it using AppHarbor's "Configuration Variables" to inject the appsettings when deployed. More information can be found in this article.
这篇关于获取原始地址,而不非标准端口(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!