dan*_*iax 13 c# rest web-services
我要在我的WCF rest webservice中检索原始请求URL.现在我的代码看起来像这样:
public class MyServiceAuthorizationManager : ServiceAuthorizationManager
{
protected override bool CheckAccessCore(OperationContext operationContext)
{
base.CheckAccessCore(operationContext);
var url = operationContext.IncomingMessageProperties.Via.OriginalString;
...
Run Code Online (Sandbox Code Playgroud)
web.config中
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
如果我的原始网址是
http://192.168.1.100:8081/test
这段代码返回
有没有办法检索确切的原始请求网址?
注意
我在web.config中找到了关于cutomize"baseAddress"标签的帖子,但是我的扩展名webservice没有特定的端点,我不想添加它.我不知道是否有办法在没有端点的情况下做到这一点.
我发现这篇文章 /sf/answers/414099941/与System.Net.HttpRequestHeader.Host一起播放,但是端口号不起作用!我知道我可以解析提供的URL并进行替换但是......我不认为这是实现此目的的最佳实践.
小智 29
System.ServiceModel.Web.WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri.OriginalString;
Run Code Online (Sandbox Code Playgroud)
这给出了原始URI.
简短回答: var url = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;
答案很长:请参阅如何在C#中获取当前页面的URL.
警告:仅当您在web.config文件中启用aspNetCompatibilityEnabled时才有效.
归档时间: |
|
查看次数: |
34508 次 |
最近记录: |