我想知道在 ASP.NET 中获取当前域的最佳方法是什么?
例如:
http://www.domainname.com/subdir/应该产生 http://www.domainname.com http://www.sub.domainname.com/subdir/应该产生 http://sub.domainname.com
作为指导,我应该能够将像“/Folder/Content/filename.html”这样的 url(比如由 ASP.NET MVC 中的 Url.RouteUrl() 生成的)直接添加到 URL 上,并且它应该可以工作.
最佳答案
与 MattMitchell 的答案相同,但有一些修改。 这会检查默认端口。
Edit: Updated syntax and using
Request.Url.Authority
as suggested
$"{Request.Url.Scheme}{System.Uri.SchemeDelimiter}{Request.Url.Authority}"
关于asp.net - ASP.NET 中获取当前域的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61817/