HttpContext.Current.Request.RawUrl的WCF等效项是什么? [英] What is the WCF equivalent of HttpContext.Current.Request.RawUrl?

查看:130
本文介绍了HttpContext.Current.Request.RawUrl的WCF等效项是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些在纯WCF上下文中运行的RESTful服务(即未启用ASP.NET兼容性,因此没有HttpContext.Current对象可用).

I've got some RESTful services running in a pure WCF context (i.e. ASP.NET compatibility is not enabled, and thus there is no HttpContext.Current object available).

在请求开始时,使用IHttpModule重写服务的URL(当时,该URL确实具有HttpContext并使用HttpContext.Current.RewritePath重写),以摆脱诸如.svc网址中的扩展名.

The URLs to the services are rewritten at the start of the request using an IHttpModule (which at that point does have an HttpContext and rewrites it using HttpContext.Current.RewritePath) to get rid of things like the .svc extension from the URL.

但是,我需要访问WCF基础结构中所请求的原始URL.在任何地方的OperationContextWebOperationContext类上是否有与HttpContext.Current.Request.RawUrl等效的东西?使用WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri返回重写的URL,而不是原始URL.

However, I need to access the original URL that was requested from within the WCF infrastructure. Is there an equivalent to HttpContext.Current.Request.RawUrl on the OperationContext or WebOperationContext classes anywhere? Using WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri returns the rewritten URL not the original one.

推荐答案

您可以通过执行以下操作获取当前目标的端点和其Uri:

You can get the endpoint currently targeted and the Uri for it by doing:

OperationContext.Current.RequestContext.RequestMessage.Headers.To

我认为与

相同:

which I think is the same thing as:

OperationContext.Current.IncomingMessageHeaders.To

这是一个System.Uri对象,我相信您可以从其中获得OriginalStringPathAndQuery或任何想要的零件.

This is a System.Uri object, and I believe you can just get the OriginalString or PathAndQuery, or whatever parts you want from it.

这篇关于HttpContext.Current.Request.RawUrl的WCF等效项是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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