Ami*_*yed 34 c# asp.net http httpcontext
我有一个本地应用程序有一个路径:
http://localhost:950/m/pages/Searchresults.aspx?search=knife&filter=kitchen
Run Code Online (Sandbox Code Playgroud)
但是当它进入集成环境或生产时,它就会像
http://www.someshopping.com/m/pages/SearchResults.aspx?search=knife&filter=kitchen
Run Code Online (Sandbox Code Playgroud)
在某些情况下,我需要通过:
www.someshopping.com
Run Code Online (Sandbox Code Playgroud)
到我的XSLT文件和我正在使用的函数之一:
string currentURL = HttpContext.Current.Request.Url.Host;
Run Code Online (Sandbox Code Playgroud)
这会在本地环境中返回" localhost ".相同的代码会回复我:
www.someshopping.com在制作中(我不需要http://)
只是不想冒任何机会.所以问这个愚蠢的问题.
edh*_*tig 41
是的,只要您在浏览器www.someshopping.com中键入的URL并且您没有使用url重写
string currentURL = HttpContext.Current.Request.Url.Host;
Run Code Online (Sandbox Code Playgroud)
将返回 www.someshopping.com
请注意本地调试环境和生产环境之间的区别
Tej*_*ejs 18
该Host
属性将返回您在访问站点时使用的域名.因此,在您的开发环境中,因为您正在请求
http://localhost:950/m/pages/Searchresults.aspx?search=knife&filter=kitchen
Run Code Online (Sandbox Code Playgroud)
它正在回归localhost
.您可以像这样拆分您的网址:
Protocol: http
Host: localhost
Port: 950
PathAndQuery: /m/pages/SearchResults.aspx?search=knight&filter=kitchen
Run Code Online (Sandbox Code Playgroud)
试试这个:
string callbackurl = Request.Url.Host != "localhost"
? Request.Url.Host : Request.Url.Authority;
Run Code Online (Sandbox Code Playgroud)
这适用于本地和生产环境.因为本地使用url和端口号是不可能使用Url.Host.
归档时间: |
|
查看次数: |
96987 次 |
最近记录: |