' IUserIdentity'不包含' Identity'

时间:2015-11-17 21:40:15

标签: c# .net visual-studio-2015 nancy

我尝试使用南希无状态身份验证示例,但我收到了IUserIdentity错误,我不明白。以下是Nancy的样本代码

using Nancy;
using Nancy.Security;
using Models;

public class SecureModule : NancyModule
{
    //by this time, the api key should have already been pulled out of our querystring
    //and, using the api key, an identity assigned to our NancyContext
    public SecureModule()
    {
        this.RequiresAuthentication();

        Get["secure"] = x =>
        {
            //Context.CurrentUser was set by StatelessAuthentication earlier in the pipeline
            var identity = this.Context.CurrentUser;

            //return the secure information in a json response
            var userModel = new UserModel(identity.Identity.Name);
            return this.Response.AsJson(new
            {
                SecureContent = "here's some secure content that you can only see if you provide a correct apiKey",
                User = userModel
            });
        };
    }
}

这是我看到的错误。

  

错误CS1061 IUserIdentity不包含Identity的定义,也无法找到接受类型为Identity的第一个参数的扩展方法IUserIdentity

当我从Nancy的示例项目中检查this.Context.CurrentUser时,它说currentuser来自ClaimsPrincipal,但当我将示例代码放入我的项目时,它会说currentuser来自IUserIdentity。 任何帮助将/将不胜感激。感谢。

1 个答案:

答案 0 :(得分:0)

在将Context CurrentUser设置为IPrinciple的{​​{3}}中。你有一个可以调整CurrentUser属性的引导程序吗?

以下是他们在演示引导程序中使用的代码(上面链接):

ctx.CurrentUser = new ClaimsPrincipal(new ClaimsIdentity(BuildClaims(username), "querystring"));