将OWIN App部署在IIS上 要想将Owin App部署在IIS上,只添加Package:Microsoft.OWIN.Host.SystemWeb包即可.它提供了所有Owin配置,Middleware注册等方面的Api.我们需要做的其实和SelfHost差不多. 我们依然需要实现Startup类,但是不是通过WebApp来启动了.我们需要通过将Startup类打上[assembly: OwinStartup(typeof(Startup))]来定义这是OWIN的Startup类,当应用运行…
Asp.net Web Api提供了RESTFul web服务的编程接口.默认RESTFul 服务没有提供任何验证或者基于角色的验证,这显然不适合Put.Post.Delete这些操作.Aps.net MVC提供了认证过滤器,结合Http基本认证,可以很好的实现RESTFul服务的认证.选择Http基本认证有以下几个原因. Http & RESTFul是无状态的,每次请求都需要认证即需要提供认证消息.将这些信息放在HTTP头部是个不错的选择. Http基本认证逻辑清晰简单,配合HTTP响应码(4…
在前一篇博文中,我们使用OAuth的Client Credential Grant授权方式,在服务端通过CNBlogsAuthorizationServerProvider(Authorization Server的一个实现)成功发放了Access Token,并在客户端成功拿到了Access Token. 那Access Token有什么用呢?在OAuth中对Resource Server(比如Web API)访问权限的验证都是基于Access Token.不管是什么样的客户端来调用,Reso…
1.自定义异常处理过滤器 /// <summary> /// 自定义异常处理过滤器 /// </summary> public class CustomExceptionFilterAttribute : ExceptionFilterAttribute { public override void OnException(HttpActionExecutedContext actionExecutedContext) { var exception = actionExecute…
在前一篇博文中,我们通过以 OAuth 的 Client Credential Grant 授权方式(只验证调用客户端,不验证登录用户)拿到的 Access Token ,成功调用了与用户无关的 Web API. 在这篇博文中,我们将以 OAuth 的 Resource Owner Password Credentials Grant 的授权方式( grant_type=password )获取 Access Token,并以这个 Token 调用与用户相关的 Web API. 对应的应用场景是…
HTTP协议中的压缩 Http协议中使用Accept-Encoding和Content-Encoding头来表示期望Response内容的编码和当前Request的内容编码.而Http内容的压缩其实是内容编码的子集.所以也通过这两个头来描述Http Request和Response内容的压缩方式. 常用的压缩算法有gzip(采用GNU zip压缩)和deflate(采用zlib的格式压缩),对应的Http头中的值也为:gzip或者deflate. 内容压缩与解压 Web服务器可以配置进行全局压缩…
一.定义一个异常筛选器 using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Http.Filters;using System.Net;using System.Net.Http; namespace WebApi{    public class NotImplExceptionFilter:ExceptionFilterAttribute    { …
授权完成添加属性 ClaimsIdentity oAuthIdentity = await CreateAsync(user/*userManager*/, OAuthDefaults.AuthenticationType, result); //oAuthIdentity.AddClaim(new Claim("proid", names[0])); //ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityA…
本文转自:http://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2-jwt-owin-authorization-server/ In the previous post Decouple OWIN Authorization Server from Resource Server we saw how we can separate the Authorization Server and the Resource Ser…
In the previous post Decouple OWIN Authorization Server from Resource Server we saw how we can separate the Authorization Server and the Resource Server by unifying the “decryptionKey” and “validationKey” key values in machineKey node in the web.conf…