获取 ASMX 中的当前域

发布于 2024-09-12 18:33:05 字数 320 浏览 1 评论 0原文

在 C# 中的 asmx Web 服务中,如何获取调用 Web 服务的当前域? HttpContext.Current.Request.Url.Host 返回我想要的内容,但不是 http://mydomain.com/文件夹/Mywebservice.asmx 我只需要http://mydomain.com。 我知道我可以把那根绳子剪断,但它看起来真的很不优雅。 谢谢

In C# in an asmx web service how do I get the current domain that the webservice was called on?
HttpContext.Current.Request.Url.Host returns kindof what I want but instead of http://mydomain.com/Folder/Mywebservice.asmx I just need http://mydomain.com.
I know i could just cut that string up but it seems really in-elegant.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鯉魚旗 2024-09-19 18:33:05

Uri.GetLeftPart 帮助这里:

Request.Url.GetLeftPart(UriPartial.Authority)

Uri.GetLeftPart helps here:

Request.Url.GetLeftPart(UriPartial.Authority)
时光病人 2024-09-19 18:33:05

在 VB.Net 中我使用过...

With HttpContext.Current.Request.Url
    sDomain=.Scheme & System.Uri.SchemeDelimiter & .Host
End With

或者如果您关心端口那么...

With HttpContext.Current.Request.Url
    sDomain=.Scheme & System.Uri.SchemeDelimiter & .Host & IIf(.IsDefaultPort,"",":") & .Port
End With

应该很容易转换为 C# ;)

In VB.Net I have used...

With HttpContext.Current.Request.Url
    sDomain=.Scheme & System.Uri.SchemeDelimiter & .Host
End With

Or if you care about the Port then...

With HttpContext.Current.Request.Url
    sDomain=.Scheme & System.Uri.SchemeDelimiter & .Host & IIf(.IsDefaultPort,"",":") & .Port
End With

Should be easy to convert to C# ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文