ASP.Net的WebAPI找不到Request.GetOwinContext [英] ASP.Net WebAPI can't find 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。这里是我的code:
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:<一href=\"http://msdn.microsoft.com/en-us/library/system.net.http.owinhtt$p$pquestmessageextensions.getowincontext(v=vs.118).aspx\">http://msdn.microsoft.com/en-us/library/system.net.http.owinhtt$p$pquestmessageextensions.getowincontext(v=vs.118).aspx
的NuGet包在这里:<一href=\"https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Owin\">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.
这篇关于ASP.Net的WebAPI找不到Request.GetOwinContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!