是什么在ASP.NET最好的方法来获取当前域? [英] What's the best method in ASP.NET to obtain the current domain?

查看:109
本文介绍了是什么在ASP.NET最好的方法来获取当前域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道什么来获取当前域的最佳途径是ASP.NET?

I am wondering what the best way to obtain the current domain is in ASP.NET?

例如:

http://www.domainname.com/subdir/ 应该产生 http://www.domainname.com
http://www.sub.domainname.com/subdir/ 应该产生的 http://sub.domainname.com

http://www.domainname.com/subdir/ should yield http://www.domainname.com http://www.sub.domainname.com/subdir/ should yield http://sub.domainname.com

作为指导,我应该能够添加一个网址,如/Folder/Content/filename.html(比如由Url.RouteUrl()在ASP.NET MVC中产生的)直接到URL,它应该工作

As a guide, I should be able to add a url like "/Folder/Content/filename.html" (say as generated by Url.RouteUrl() in ASP.NET MVC) straight onto the URL and it should work.

推荐答案

相同的答案MattMitchell的,但有一些修改。
此检查的默认端口。

Same answer as MattMitchell's but with some modification. This checks for the default port instead.

Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host +
(Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port)

这篇关于是什么在ASP.NET最好的方法来获取当前域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆