Tag: owin asp.net web api2

结构图Web Api 2帐户控制器和个人帐户

我非常喜欢IOC和web-api 2,但是我已经使用了StructureMap来处理web-api中我自己的控制器2.我没有管理的是使用个人帐户在AccountController上使用StructureMap。 我使用AccountController开箱即用,到目前为止我所管理的是: 在Ioc.cs中我添加了以下内容(由于错误) x.For<IUserStore>().Use<UserStore>(); x.For().Use(() => new ApplicationDbContext()); x.For<ISecureDataFormat() .Use<SecureDataFormat>(); 但是现在我遇到了这个错误: “没有注册默认实例,无法自动确定类型IDataSerializer ” 我真的不知道该怎么做。 我试图找到IDataSerializer的详细实例,但没有运气。 顺便说一句……我已经安装了Nuget包“Structuremap.webapi2”

WebApp.Start 方法类型参数

在基于本文使用Owin将我的Windows服务应用程序设置为自托管主机: http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api 我使用了WebApp.Start方法的这个重载: WebApp.Start方法(String) 这是我的代码: //(in startup method) _server = WebApp.Start(BaseAddress); public class Startup { // This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public void Configuration(IAppBuilder appBuilder) { // Configure Web API for self-host. var config = new HttpConfiguration(); config.Routes.MapHttpRoute(“DefaultApi”, “api/{controller}/{id}”, new { […]

用户(IPrincipal)在ApiController的构造函数上不可用,使用Web Api 2.1和Owin

我正在使用带有Asp.Net Identity 2的Web Api 2.1。我试图在我的ApiController的构造函数上获取经过身份validation的用户(我使用AutoFac来注入我的依赖项),但是当调用构造函数时,User显示为未经过身份validation。 我正在尝试获取用户,以便我可以为任何数据库写操作生成审核信息。 我正在做的一些事情可以帮助诊断: 我只使用app.UseOAuthBearerTokens作为Asp.Net Identity 2的身份validation。这意味着我删除了在使用Asp.Net创建新的Web Api 2.1项目时默认启用的app.UseCookieAuthentication(new CookieAuthenticationOptions())身份2。 在WebApiConfig里面我正在注入我的存储库: builder.RegisterType().As().InstancePerRequest(); 这是我的控制器: [RoutePrefix(“api/values”)] public class ValuesController : ApiController { private IValueRepository valueRepository; public ValuesController(IValueRepository repo) { valueRepository = repo; // I would need the User information here to pass it to my repository // something like this: valueRepository.SetUser(User); } protected override […]