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

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

问题描述

我有一些 RESTful 服务在纯 WCF 上下文中运行(即未启用 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).

服务的 URL 在请求开始时使用 IHttpModule 重写(此时它确实有一个 HttpContext 并使用 HttpContext 重写它.Current.RewritePath) 从 URL 中删除诸如 .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天全站免登陆