Owin管道与asp.net管道模型
------2016.3.6 更新 文中提到没有Microsoft.Owin.Host.SystemWeb 这个dll 便不会加载Startup.Configuration,因为这个dll 其中有个OwinHttpModul. 网站回加载这个modul然后在这里面实现了owin的管道(ps 就是 把owin定义的模块挂载到httpapplication的 几个事件上)。
最近一直没搞懂在 mvc5框架中 为什么存在 Global.asax.cs和Startup.cs 文件...
然后搜索下面文章:
http://stackoverflow.com/questions/20168978/do-i-need-a-global-asax-cs-file-at-all-if-im-using-an-owin-startup-cs-class-and
其中提到
1、Application_Start 会比Startup.Configuration 先启动
2、mvc4 版本一致性 布啦布啦....
3、 Global.asax.cs 可以处理一些特殊事件 例如 Application_Start Application_Error Session_Start 等等
4、Startup.Configuration 中可以配置 关于授权之类的(替代原先的Application_AuthenticateRequest,另外mvc5中引入了ASP.NET Identity 2,而这个基于Owin)
5、最最重要的一条如果 引用集没有Microsoft.Owin.Host.SystemWeb 这个dll 便不会加载Startup.Configuration
----------------------分割线----------------------------------
ok 进入另一个话题 owin 的管道有什么 首先贴下微软的PipelineStage
namespace Owin
{
/// <summary>
/// An ordered list of known Asp.Net integrated pipeline stages. More details on the ASP.NET integrated pipeline can be found at http://msdn.microsoft.com/en-us/library/system.web.httpapplication.aspx
///
/// </summary>
public enum PipelineStage
{
Authenticate,
PostAuthenticate,
Authorize,
PostAuthorize,
ResolveCache,
PostResolveCache,
MapHandler,
PostMapHandler,
AcquireState,
PostAcquireState,
PreHandlerExecute,
}
}
看注释 去看 httpapplication事件。。。个人感觉Owin管道里的事件是可以替代原先的httpapplication事件的。。。
--------------------------------------------分割线-----------------------------------------------------
既然说到Startup.Configuration可以替代 那怎么用才是关键,直接上代码:
public void Configuration(IAppBuilder app)
{
app.Use((context, next) =>
{
PrintCurrentIntegratedPipelineStage(context, "Middleware 1");
return next.Invoke();
});
app.Use((context, next) =>
{
PrintCurrentIntegratedPipelineStage(context, "2nd MW");
return next.Invoke();
});
app.UseStageMarker(PipelineStage.Authenticate);
app.Run(context =>
{
PrintCurrentIntegratedPipelineStage(context, "3rd MW");
return context.Response.WriteAsync("Hello world");
});
app.UseStageMarker(PipelineStage.ResolveCache);
}
看代码中红色部分。。。 使用app.UseStageMarker(xxxx状态)之前的代码 便是xxxx状态注册。
注意:
1、如果不是用UseStageMarker标记 那些中间件的位置 所有的位置为:PreHandlerExecute。
2、多次使用UseStageMarker 不能 前面顺序比后面大。。。
相关链接:http://www.asp.net/aspnet/overview/owin-and-katana/owin-middleware-in-the-iis-integrated-pipeline
----------------------------分割线-----------------------------------------------------------
个人一些闲言碎语
貌似 asp.net5 里 mvc框架 中没有了Global.asax.cs文件 入口就是Startup.cs
还有 个人感觉 IOwinConent 会替代 HttpAplication ;OwinMiddleware 替代IHttpModule ( 当然这是指 asp.net5里,而mvc5中还是 混搭风格),app.Use(xxxxxx)构成的 管道还是 相对好理解的
不过现在asp.net 还是 rc等出了 rtm再来更新吧。。。。
贴下 asp.net5中Startup
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using WebApplication2.Models;
using WebApplication2.Services; namespace WebApplication2
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
} builder.AddEnvironmentVariables();
Configuration = builder.Build();
} public IConfigurationRoot Configuration { get; set; } // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders(); services.AddMvc(); // Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug(); if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error"); // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
try
{
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
.CreateScope())
{
serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
.Database.Migrate();
}
}
catch { }
} app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear()); app.UseStaticFiles(); app.UseIdentity(); // To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} // Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}
}
Owin管道与asp.net管道模型的更多相关文章
- iis与 asp.net管道(asp.net应用程序什么周期)
iis5和iis6.0下面,把iis的管道和asp.net管道进行了隔离,带来了一些局限和不足. 比如: 1.iis和asp.net之间有一些相同的操作.比如:身份认证. 2.动态文件和静态文件的 ...
- Asp.net管道模型(管线模型)
Asp.net管道模型(管线模型) 前言 为什么我会起这样的一个标题,其实我原本只想了解asp.net的管道模型而已,但在查看资料的时候遇到不明白的地方又横向地查阅了其他相关的资料,而收获比当初预 ...
- Asp.net管道模型(管线模型)之一发不可收拾
前言 为什么我会起这样的一个标题,其实我原本只想了解asp.net的管道模型而已,但在查看资料的时候遇到不明白的地方又横向地查阅了其他相关的资料,而收获比当初预想的大了很多. 有本篇作基础,下面两篇就 ...
- asp.net 管道模型+生命处理周期
http://www.cnblogs.com/qianlifeng/archive/2010/12/16/1908568.html https://msdn.microsoft.com/zh-cn/l ...
- Asp.Net MVC<二> : IIS/asp.net管道
MVC是Asp.net的设计思想,而IIS/asp.net是它的技术平台.理解ASP.NET的前提是对ASP.NET管道式设计的深刻认识.而ASP.NET Web应用大都是寄宿于IIS上的. IIS ...
- IIS/asp.net管道
http://referencesource.microsoft.com/ 理解ASP.NET的前提是对ASP.NET管道式设计的深刻认识.而ASP.NET Web应用大都是寄宿于IIS上的. IIS ...
- ASP.NET Core管道深度剖析(2):创建一个“迷你版”的管道来模拟真实管道请求处理流程
从<ASP.NET Core管道深度剖析(1):采用管道处理HTTP请求>我们知道ASP.NET Core请求处理管道由一个服务器和一组有序的中间件组成,所以从总体设计来讲是非常简单的,但 ...
- IIS与ASP.NET管道
IIS 5.x与ASP.NET 我们先来看看IIS 5.x是如何处理基于ASP.NET资源(比如.aspx,.asmx等)请求的,整个过程基本上可以通过图1体现. IIS 5.x运行在进程InetIn ...
- ASP.NET管道
以IIS 6.0为例,在工作进程w3wp.exe中,利用Aspnet_ispai.dll加载.NET运行时(如果.NET运行时尚未加载).IIS 6引入了应用程序池的概念,一个工作进程对应着一个应用程 ...
随机推荐
- hdu 4333(扩展kmp)
题意:就是给你一个数字,然后把最后一个数字放到最前面去,经过几次变换后又回到原数字,问在这些数字中,比原数字小的,相等的,大的分别有多少个.比如341-->134-->413-->3 ...
- codeforces 340B Maximal Area Quadrilateral(叉积)
事实再一次证明:本小菜在计算几何上就是个渣= = 题意:平面上n个点(n<=300),问任意四个点组成的四边形(保证四条边不相交)的最大面积是多少. 分析: 1.第一思路是枚举四个点,以O(n4 ...
- app如何节省流量
前言:“客户端上传时间戳”的玩法,你玩过么?一起聊聊时间戳的奇技淫巧! 缘起:无线时代,流量敏感.APP在登录后,往往要向服务器同步非常多的数据,很费流量,技术上有没有节省流量的方法呢?这是本文要讨论 ...
- 可进行JavaScript代码测试与调试的12个网站
概述:JavaScript是网站前端开发最为重要的一门编程语言,本文收集了能够在线测试与调试JavaScript代码的12个网站 1.JS Bin JS bin是一个为JavaScript和CSS爱好 ...
- JavaScript对象(窗口对象 定时器对象 )
1:窗口时间 confirm(str):确认对话框,确认返回trun,取消返回false,但是必须要有两个return:不然就算按下取消也会提交 第一个return:用于保证确认按钮运行 <sc ...
- iOS学习笔记之ARC内存管理
iOS学习笔记之ARC内存管理 写在前面 ARC(Automatic Reference Counting),自动引用计数,是iOS中采用的一种内存管理方式. 指针变量与对象所有权 指针变量暗含了对其 ...
- C++11 现代C++风格的新元素--简介
C++11标准推出了很多有用的新特性,本文特别关注那些相比C++98更像是一门新语言的特性,理由是: 这些特性改变了编写C++程序使用的代码风格和习语[译注 1],通常也包括你设计C++函数库的方式. ...
- static public和 public static 区别
static:加static 的是静态成员,不能实例化在你运行的时候他自己在内存中开辟了块空间,不用在new, 有点像全局变量,如果不用你必须去 实例化(new)才能用 static是静态的意思,pu ...
- SNMP 和 NetBios协议理解
一.简单网络管理协议(SNMP,Simple Network Management Protocol)构成了互联网工程工作小组(IETF,Internet Engineering Task For ...
- 本地虚拟机挂载windows共享目录搭建开发环境
关闭防火墙(本地环境 直接关掉即可)service iptables stop检查是否安装了需要的samba软件包rpm –q samba如果没安装yum install samba system-c ...