ホスト ヘッダーの API キーを使用して呼び出しを認証するように ServiceStack を構成できるかどうかを確認しようとしています。
ここで例を見つけました: http://rossipedia.com/blog/2013/03/06/simple-api-key-authentication-with-servicestack/
しかし、何らかの理由で、私の Clients.cs では次のようになります。
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
namespace Servicestack_MVC.Models
{
public static class Clients
{
private static Lazy<ClientSection> section = new Lazy<ClientSection>(() =>
(ClientSection)ConfigurationManager.GetSection("apiClients"));
public static bool VerifyKey(string apiKey)
{
return section.Value.Cast<ClientSection.ClientElement>()
.SingleOrDefault(ce => ce.ApiKey == apiKey);
}
}
}
エラーが発生します:
エラー 9 インスタンス引数: 'Servicestack_MVC.Models.ClientSection' から 'System.Linq.IQueryable' に変換できません。
エラー 10 'Servicestack_MVC.Models.ClientSection' には 'Cast' の定義が含まれておらず、最適な拡張メソッド オーバーロード 'System.Linq.Queryable.Cast(System.Linq.IQueryable)' に無効な引数が含まれています
web.config のセクションに次を追加しました。
<section name="apiClients" type="ClientSection" requirePermission="false"/>
セクションを追加しました
<apiClients>
<clients>
<client name="Client1" apiKey="somelongrandomkey" />
<client name="Client2" apiKey="somelongrandomkey" />
<!-- etc -->
</clients>
</apiClients>
誰が私が間違っているのか教えてもらえますか?
どうもありがとう