gpt4 book ai didi

c# - 在 WCF REST 服务中获取原始请求 url

转载 作者:可可西里 更新时间:2023-11-01 08:02:10 24 4
gpt4 key购买 nike

我必须在我的 WCF rest web 服务中检索原始请求 url。现在我的代码如下所示:

public class MyServiceAuthorizationManager : ServiceAuthorizationManager
{
protected override bool CheckAccessCore(OperationContext operationContext)
{
base.CheckAccessCore(operationContext);

var url = operationContext.IncomingMessageProperties.Via.OriginalString;
...

网络配置

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>

如果我原来的网址是

http://192.168.1.100:8081/test

这段代码返回

http://hostname:8081/test

有没有办法检索准确的原始请求 url?

注意

我在 web.config 中找到了谈论 cutomize“baseAddress”标签的帖子,但我没有来 self 的 extensionles web 服务的特定端点,我不想添加它。我不知道是否有没有端点的方法。

我找到了这篇文章 https://stackoverflow.com/a/5915713/735864与 System.Net.HttpRequestHeader.Host 一起玩,但端口号不起作用!我知道我可以解析提供的 url 并进行替换,但是...我认为这不是实现此目的的最佳做法。

最佳答案

System.ServiceModel.Web.WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri.OriginalString;

这给出了原始 URI。

关于c# - 在 WCF REST 服务中获取原始请求 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9110397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com