小编Bre*_*ans的帖子

为什么我会得到"无法解析符号'CreatePerOwinContext'"?

我有一个自我托管的Owin Web Api,我正在尝试使用每个Owin请求的EF Context的单个实例.这是我的启动类的配置代码.

public void Configuration(IAppBuilder app)
{         
    app.CreatePerOwinContext(A3Context.Create);
}
Run Code Online (Sandbox Code Playgroud)

这不会构建,因为我收到以下错误.

错误

5'Enterin.IAppBuilder'不包含'CreatePerOwinContext'的定义,并且没有扩展方法'CreatePerOwinContext'接受类型'Owin.IAppBuilder'的第一个参数'(你是否缺少using指令或汇编引用?)

我错过了一个我不知道的参考文献?

c# asp.net self-hosting owin

10
推荐指数
1
解决办法
5363
查看次数

如何使用JWT对角度SPA的Web Api 2进行用户身份验证?

我正在尝试将AngularJS单页面应用程序(SPA)中的身份验证设置为基于OWIN构建的Web Api.这是我的......

这是登录功能(API中的AuthenticationController上的POST操作)

public HttpResponseMessage login(Credentials creds)
    {
        if (creds.Password == "password" && creds.Username.ToLower() == "username")
        {
            var user = new User { UserId = 101, Name = "John Doe", Role = "admin" };

            var tokenDescriptor = new SecurityTokenDescriptor()
            {
                Subject = new ClaimsIdentity(new[]
                {
                    new Claim(ClaimTypes.Name, user.Name), 
                    new Claim(ClaimTypes.Role, user.Role)
                }),

                AppliesToAddress = "http://localhost:/8080",
                TokenIssuerName = "myApi",

                SigningCredentials = new SigningCredentials(new InMemorySymmetricSecurityKey(TestApp.Api.Startup.GetBytes("ThisIsTopSecret")),
                    "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256",
                    "http://www.w3.org/2001/04/xmlenc#sha256")
            };

            var tokenHandler = new JwtSecurityTokenHandler();
            var token = tokenHandler.CreateToken(tokenDescriptor);
            var tokenString = tokenHandler.WriteToken(token);

            return …
Run Code Online (Sandbox Code Playgroud)

asp.net jwt asp.net-web-api angularjs owin

5
推荐指数
1
解决办法
4161
查看次数

在Web API 2.2上使用带有Odata v4.0的$ select和$ expand时出错

我有一个为OData v4配置的web api 2.2.我希望按ID返回用户,并且仅包含用户所属的用户组ID.当我这样做

http://localhost/User?$filter=id eq 312&$select=*,userGroups/id&$expand=userGroups
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

URI中指定的查询无效.在select子句中找到具有多个导航属性的路径.请重新设置您的查询,以便每个级别的select或expand仅包含TypeSegments或Properties.

在select子句中找到具有多个导航属性的路径.请重新设置您的查询,以便每个级别的select或expand仅包含TypeSegments或Properties.

如果我删除",userGruops/id",查询将执行

odata asp.net-web-api2 odata-v4

5
推荐指数
1
解决办法
1823
查看次数