首页 技术 正文
技术 2022年11月9日
0 收藏 725 点赞 3,287 浏览 1647 个字

Open Web Interface for .NET (OWIN)在Web服务器和Web应用程序之间建立一个抽象层。OWIN将网页应用程序从网页服务器分离出来,然后将应用程序托管于OWIN的程序而离开IIS之外,关于OWIN的详细资料可参考博客 MVC5 – ASP.NET Identity登录原理 – Claims-based认证和OWIN。使用OWIN 自宿主 ASP.NET WebAPI 2可以参考以下2篇文章:

  1. Use OWIN to Self-Host ASP.NET Web API 2
  2. Asp.Net Web API 2第十课——使用OWIN自承载Web API

我们看下配置代码:

using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;namespace OWinSelfHost
{
public class Startup
{
public void Configuration(IAppBuilder appBuilder)
{
// Configure Web API for self-host.
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
); appBuilder.UseWebApi(config);
}
}
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

每个OWIN应用程序都需要一个Startup类作为OWIN管道中的配置类,ASP.NET Web API OWIN Self Hosting 基于约定胜于配置来找到Startup的一个Configuration方法。 UseWebApi 方法通过 ASP.NET Web API 框架 动态的将配置添加到 IAppBuilder。当调用 UseWebApi 时,ASP.NET Web API 中间件组件被添加到OWIN管道中用所提供的 HTTPConfiguration 对象。

ASP.NET Web API 仍然使用现有的 HttpConfiguration 类来定义路由等。另外说明下,通过OWIN宿主ASP.NET WebAPI还可以完美的兼容Mono 3哦。

 

Protecting a Self-Hosted API with Microsoft.Owin.Security.ActiveDirectory

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,294