HttpContext.Current.Request.RawUrl的WCF等效项是什么? [英] What is the WCF equivalent of HttpContext.Current.Request.RawUrl?
问题描述
我有一些在纯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.在任何地方的OperationContext
或WebOperationContext
类上是否有与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
对象,我相信您可以从其中获得OriginalString
或PathAndQuery
或任何想要的零件.
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屋!