在页眉的OperationContext

编程入门 行业动态 更新时间:2024-10-26 06:31:45
本文介绍了在页眉的OperationContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我会做一个小项目(WCF + REST),我有一个小问题。我希望让我的授权和身份验证类。

I'd make a little project (WCF + REST) and I have a small problem. I want make my Authorization and Authentication class.

我的授权类:

//validate api key public class BasicAuthorization : ServiceAuthorizationManager { public override bool CheckAccess(OperationContext operationContext, ref Message message) { //some code } }

我的身份验证类

// validation user login & password public class BasicAuthentication : ServiceAuthenticationManager { public override ReadOnlyCollection<IAuthorizationPolicy> Authenticate( ReadOnlyCollection<IAuthorizationPolicy> authPolicy, Uri listenUri, ref Message message) { //some code } }

我有太多一些配置文件

<behavior> <serviceAuthorization serviceAuthorizationManagerType="WCF.BasicAuthorization, WCF"/> <serviceAuthenticationManager serviceAuthenticationManagerType="WCF.BasicAuthentication, WCF"/> </behavior>

在类的代码是不重要的 - 是没有问题的。

The code in class is unimportant - is not a problem.

我的问题是如何从的OperationContext或消息类获得头。以前我怎么说,我有这样的休息,所以我想手动设置Authorizaion头/ WWW-Authenticate头,但应用程序不会看到它。

My problem is how to get Headers from operationContext or message class. How i say before, i make this in rest, so i want manual set Authorizaion header / www-authenticate header, but application doesn't see it.

我打开在Fiddler2,并尝试提出的任何标题,例如:

I turn on the Fiddler2, and try put any header for example :

Content-Type: application/xml Authorization: Basic bla23rwerfsd3== User-Agent: Fiddler Host: localhost:59305

和在message.Headers / operationContext.Headers不会有任何我的头(只等一个),没有授权,任何内容类型

And the message.Headers / operationContext.Headers doesn't has any my header (has only other one), no Authorization, no Content-Type

推荐答案

您可以使用System.ServiceModel.Web.WebOperationContext类,它有一个静态属性当前,它代表了当前上下文你的网络运行期间访问头。它提供了包含类型WebHeaderCollection一个头属性的IncomingRequest属性。

You can access the headers during your web-operation using the System.ServiceModel.Web.WebOperationContext class, which has a static property "Current", which represents the current-context. It provides an "IncomingRequest" property that contains a "Header" property of type "WebHeaderCollection".

更多推荐

在页眉的OperationContext

本文发布于:2023-11-05 04:14:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559871.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:页眉   OperationContext

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!