integration asp.net web api with autofac and owin
There is an example project showing Web API in conjunction with OWIN self hosting
https://github.com/autofac/Examples/tree/master/src/WebApiExample.OwinSelfHost
https://github.com/autofac/Examples/blob/master/src/WebApiExample.OwinSelfHost/Startup.cs
Owin
https://autofaccn.readthedocs.io/en/latest/integration/owin.html
OWIN (Open Web Interface for .NET) is a simpler model for composing web-based applications without tying the application to the web server. To do this, a concept of “middleware” is used to create a pipeline through which requests travel.
Due to the differences in the way OWIN handles the application pipeline (detecting when a request starts/ends, etc.) integrating Autofac into an OWIN application is slightly different than the way it gets integrated into more “standard” ASP.NET apps. You can read about OWIN and how it works on this overview.
The important thing to remember is that order of OWIN middleware registration matters. Middleware gets processed in order of registration, like a chain, so you need to register foundational things (like Autofac middleware) first.
Quick Start
To take advantage of Autofac in your OWIN pipeline:
- Reference the
Autofac.Owin
package from NuGet. - Build your Autofac container.
- Register the Autofac middleware with OWIN and pass it the container.
Web api integration with owin
https://autofaccn.readthedocs.io/en/latest/integration/webapi.html#owin-integration
If you are using Web API as part of an OWIN application, you need to:
- Do all the stuff for standard Web API integration - register controllers, set the dependency resolver, etc.
- Set up your app with the base Autofac OWIN integration.
- Add a reference to the Autofac.WebApi2.Owin NuGet package.
- In your application startup class, register the Autofac Web API middleware after registering the base Autofac middleware.
A common error in OWIN integration is use of the GlobalConfiguration.Configuration
.
In OWIN you create the configuration from scratch.
You should not reference GlobalConfiguration.Configuration
anywhere when using the OWIN integration.
integration asp.net web api with autofac and owin的更多相关文章
- (转)【ASP.NET Web API】Authentication with OWIN
概述 本文说明了如何使用 OWIN 来实现 ASP.NET Web API 的验证功能,以及在客户端与服务器的交互过程中,避免重复提交用户名和密码的机制. 客户端可以分为两类: JavaScript: ...
- 在ASP.NET Web API 2中使用Owin OAuth 刷新令牌(示例代码)
在上篇文章介绍了Web Api中使用令牌进行授权的后端实现方法,基于WebApi2和OWIN OAuth实现了获取access token,使用token访问需授权的资源信息.本文将介绍在Web Ap ...
- 在ASP.NET Web API 2中使用Owin基于Token令牌的身份验证
基于令牌的身份验证 基于令牌的身份验证主要区别于以前常用的常用的基于cookie的身份验证,基于cookie的身份验证在B/S架构中使用比较多,但是在Web Api中因其特殊性,基于cookie的身份 ...
- ASP.NET Web API 安全筛选器
原文:https://msdn.microsoft.com/zh-cn/magazine/dn781361.aspx 身份验证和授权是应用程序安全的基础.身份验证通过验证提供的凭据来确定用户身份,而授 ...
- ASP.NET Web API安全认证
http://www.cnblogs.com/codeon/p/6123863.html http://open.taobao.com/docs/doc.htm?spm=a219a.7629140.0 ...
- [转] JSON Web Token in ASP.NET Web API 2 using Owin
本文转自:http://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2-jwt-owin-authorization-server/ ...
- JSON Web Token in ASP.NET Web API 2 using Owin
In the previous post Decouple OWIN Authorization Server from Resource Server we saw how we can separ ...
- Autofac ASP.NET Web API (Beta) Integration
With the beta release of ASP.NET MVC 4 and the ASP.NET Web API being released a few weeks ago, I dec ...
- 使用Autofac在ASP.NET Web API上实现依赖注入
在ASP.NET Web API里使用Autofac 1.通过NuGet安装Autofac.WebApi(当时安装的是Autofac 3.1.0) PM > Install-Package Au ...
随机推荐
- HAPROXY简介
HAProxy 是一款高性能TCP/HTTP 反向代理负载均衡服务器,具有如下功能: 根据静态分配的cookies完成HTTP请求转发 在多个服务器间实现负载均衡,并且根据HTTP cookies 实 ...
- 二项分布。计算binomial(100,50,0.25)将会产生的递归调用次数(算法第四版1.1.27)
算法第四版35页问题1.1.27,估计用一下代码计算binomial(100,50,0.25)将会产生的递归调用次数: public static double binomial(int n,int ...
- Apache Samza - Reliable Stream Processing atop Apache Kafka and Hadoop YARN
http://engineering.linkedin.com/data-streams/apache-samza-linkedins-real-time-stream-processing-fram ...
- 使用 postMessage + iframe 实现跨域通信
一.postMessage window.postMessage() 方法可以安全地实现跨源通信.通常,对于两个不同页面的脚本,只有当执行它们的页面位于具有相同的协议(通常为https),端口号(44 ...
- Python量化常用函数
# -*- coding: utf-8 -*- # @Author: fangbei # @Date: 2017-08-26 # @Original: price_str = '30.14, 29.5 ...
- js Ajax 跨域请求
一.使用jsonp的方式(只支持get请求) 二.使用cors的方式(支持HTTP的大部分请求方式) 三.apache的转发(修改服务器配置) 没有试验,暂时不详细写!
- 剑指Offer——按之字形顺序打印二叉树
题目描述: 请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推. 分析: 我们都知道二叉树的层次遍历用的是队 ...
- 确定比赛名次---hdu1285(拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285 拓扑序就是求一个序列 数 a 出现在数 b 前面,最终输出满足条件的序列即可: 过程就是每次选取 ...
- Win32 配置文件用法
#include "stdafx.h"#include <Shlobj.h>#include <Shlwapi.h> #pragma comment(lib ...
- C++ 带有通配符*与?的字符串匹配
题目:两个字符串,一个是普通字符串,另一个含有*和?通配符,*代表零个到多个任意字符,?代表一个任意字符,通配符可能多次出现.写一个算法,比较两个字符串是否相等. 发现许多公司笔试面试都有这道题目,于 ...