在ASP.NET中,是什么让一个请求的基本URL的最快方法? [英] In ASP.NET, what is the quickest way to get the base URl for a request?
本文介绍了在ASP.NET中,是什么让一个请求的基本URL的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种快速的方法来获取方案,主机,端口(仅如果不是80)和应用程序路径在ASP.NET?
Is there a fast way to get the scheme, host, port (only if not 80) and application path in ASP.NET?
据我知道,我需要装配以下几部分:
As far as I know, I need to assemble the following pieces:
- Request.Url.Scheme
- Request.Url.SchemeDelimiter
- Request.Url.Authority(尽管这可能会总是包括甚至当它的端口80)
- Request.ApplicationPath
是不是有一个简单的属性是什么?
Isn't there a simple property for that?
推荐答案
这应该工作:
Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath
请注意,这可能会或可能不会与一个/结尾取决于如果您的应用程序在网站的根目录或子目录主办。
Note that this may or may not end with a trailing "/" depending on if your app is hosted in the root of the site or in a sub directory.
这篇关于在ASP.NET中,是什么让一个请求的基本URL的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文