找不到Request.GetOwinContext [英] Can't find Request.GetOwinContext

查看:1442
本文介绍了找不到Request.GetOwinContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个小时试图找出为什么这是行不通的。

I have been searching for an hour trying to figure out why this isn't working.

我有一个的WebAPI一个ASP.Net MVC 5应用程序。我试图让Request.GetOwinContext()认证,但是我似乎无法找到如何将GetOwinContext。这里是我的代码:

I have a ASP.Net MVC 5 application with a WebAPI. I am trying to get Request.GetOwinContext().Authentication, however I can't seem to find how to include GetOwinContext. Here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using TaskPro.Models;

namespace TaskPro.Controllers.api
{
    public class AccountController : ApiController
    {
        [HttpPost]
        [AllowAnonymous]
        public ReturnStatus Login(LoginViewModel model)
        { 
            if (ModelState.IsValid)
            {
                var ctx = Request.GetOwinContext(); // <-- Can't find this

                return ReturnStatus.ReturnStatusSuccess();
            }

            return base.ReturnStatusErrorsFromModelState(ModelState);
        }
    }
}

这是我读过,它应该是System.Net.Http的一部分,但我已经提供了,它仍然没有解决。 Ctrl-Space键并没有给我任何的IntelliSense选项无论是。

From what I've read, it should be part of the System.Net.Http, but I've included that and it still isn't resolving. Ctrl-Space doesn't give me any intellisense options either.

我缺少的是在这里吗?

推荐答案

GetOwinContext 扩展方法是在 System.Web.Http.Owin DLL其中需要下载一个包的NuGet (该包的NuGet名称为Microsoft.AspNet.WebApi.Owin)

The GetOwinContext extension method is in the System.Web.Http.Owin dll which needs to be downloaded as a nuget package (The nuget package name is Microsoft.AspNet.WebApi.Owin)

Install-Package Microsoft.AspNet.WebApi.Owin

请参阅MSDN此处的 http://msdn.microsoft.com/en-美国/库/ system.net.http.owinhttprequestmessageextensions.getowincontext(v = vs.118)的.aspx

See msdn here: http://msdn.microsoft.com/en-us/library/system.net.http.owinhttprequestmessageextensions.getowincontext(v=vs.118).aspx

的NuGet包此处的https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Owin

Nuget package here: https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Owin

然而,这种方法仍然是 System.Net.Http 命名空间的一部分,因此使用定义应该罚款。

However, the method is still part of the System.Net.Http namespace, so the using definitions you have should be fine.

这篇关于找不到Request.GetOwinContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆