簡體   English   中英

OperationContext中的標頭

[英]Headers in OperationContext

我做了一個小項目(WCF + REST),我遇到了一個小問題。 我想創建我的授權和身份驗證類。

我的授權類:

//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>

類中的代碼不重要 - 不是問題。

我的問題是如何從operationContext或消息類中獲取Headers。 我之前怎么說,我讓它休息,所以我想手動設置Authorizaion標題/ www-authenticate標題,但應用程序沒有看到它。

我打開Fiddler2,並嘗試將任何標題放在例如:

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

而message.Headers / operationContext.Headers沒有任何我的標題(只有其他標題),沒有授權,沒有內容類型

您可以使用System.ServiceModel.Web.WebOperationContext類在Web操作期間訪問標頭,該類具有靜態屬性“Current”,表示當前上下文。 它提供了一個“IncomingRequest”屬性,其中包含“WebHeaderCollection”類型的“Header”屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM