当前位置: 首页 > news >正文

广州网站开发水平广州亦客网络如何自建网站做淘客

广州网站开发水平广州亦客网络,如何自建网站做淘客,桂林象鼻山景区官网,有没有资源可以在线观看前言 本篇文章介绍ASP.NET Core里#xff0c;用来处理HTTP封包的Middleware#xff0c;为自己留个纪录也希望能帮助到有需要的开发人员。 ASP.NET Core官网 结构 在ASP.NET Core里#xff0c;每个从「浏览器传入」的HTTP Request封包#xff0c;会被系统封装为「HttpReques… 前言 本篇文章介绍ASP.NET Core里用来处理HTTP封包的Middleware为自己留个纪录也希望能帮助到有需要的开发人员。 ASP.NET Core官网 结构 在ASP.NET Core里每个从「浏览器传入」的HTTP Request封包会被系统封装为「HttpRequest对象」并且配置默认的HttpResponse对象、Session对象、ClaimsPrincipal对象...等等物件。接着将这些对象封装成为一个「HttpContext对象」用来提供ASP.NET Core后续使用。 frameborder0 scrollingno styleborder-width: initial; border-style: none; width: 715px; height: 521px;ASP.NET Core在收到HttpContext之后会把它交给一个「Pipeline」去处理。这个Pipeline里面配置很多「Middleware」。系统会将HttpContext依序传递给Pipeline里的Middleware去处理。每个Middleware会依照自己内部的程序逻辑来运算处理HttpContext并且变更HttpContext所封装的对象内容。 frameborder0 scrollingno styleborder-width: initial; border-style: none; width: 715px; height: 521px;ASP.NET Core在收到经由Middleware处理完毕的HttpContext之后就会取出其中所封装的HttpResponse对象。然后依照这个HttpResponse对象来建立从「服务器回传」的HTTP Response封包内容。 frameborder0 scrollingno styleborder-width: initial; border-style: none; width: 715px; height: 519px;ASP.NET Core经由上述的系统结构完成HTTP Request封包输入、HTTP Response封包输出的工作流程。 frameborder0 scrollingno styleborder-width: initial; border-style: none; width: 715px; height: 519px; 开发 Invoke 在[ASP.NET Core] Getting Started这篇文章里提供了一个ASP.NET Core的Middleware范例HelloWorldMiddleware。在这个范例里Middleware透过实做Invoke方法来提供自己所封装的程序逻辑。 public class HelloWorldMiddleware {// Fieldsprivate readonly RequestDelegate _next;// Constructorspublic HelloWorldMiddleware(RequestDelegate next){_next next;}// Methodspublic Task Invoke(HttpContext context){// Responsecontext.Response.WriteAsync(Hello World!);// Returnreturn Task.CompletedTask;} } frameborder0 scrollingno styleborder-width: initial; border-style: none; width: 715px; height: 510px; HttpContext.Request 在实做Middleware.Invoke方法的时候开发人员可以透过HttpContext.Request来取得从「浏览器传入」的HTTP Request封包内容。在下列的范例程序代码里就是透过HttpContext.Request的Path、QueryString两个属性来分别取得HTTP Request封包的URL路径与QueryString内容。 public class HelloWorldMiddleware {// Fieldsprivate readonly RequestDelegate _next;// Constructorspublic HelloWorldMiddleware(RequestDelegate next){_next next;}// Methodspublic Task Invoke(HttpContext context){// Requeststring path context.Request.Path.ToString();string queryString context.Request.QueryString.ToString();string message string.Format(path{0}, queryString{1}, path, queryString);// Responsecontext.Response.WriteAsync(message);// Returnreturn Task.CompletedTask;} } frameborder0 scrollingno styleborder-width: initial; border-style: none; width: 715px; height: 510px; HttpContext.Response 同样在实做Middleware.Invoke方法的时候开发人员可以透过HttpContext.Response来设定从「服务器回传」的HTTP Response封包内容。在下列的范例程序代码里就是透过HttpContext.Response的WriteAsync方法、StatusCode属性来分别设定HTTP Response封包的Content与StatusCode。 public class HelloWorldMiddleware {// Fieldsprivate readonly RequestDelegate _next;// Constructorspublic HelloWorldMiddleware(RequestDelegate next){_next next;}// Methodspublic Task Invoke(HttpContext context){// Responsecontext.Response.StatusCode 404;context.Response.WriteAsync(Not Found);// Returnreturn Task.CompletedTask;} } frameborder0 scrollingno styleborder-width: initial; border-style: none; width: 715px; height: 510px; Exception 而在实做Middleware.Invoke方法的时候如果程序代码里发生了预期之外的Exception。ASP.NET Core预设会使用「500 Internal Server Error」这个StatusCode来通报系统内部发生异常。 在下列的范例程序代码里就是直接抛出一个例外错误交由ASP.NET Core的错误处理机制去处理。 public class HelloWorldMiddleware {// Fieldsprivate readonly RequestDelegate _next;// Constructorspublic HelloWorldMiddleware(RequestDelegate next){_next next;}// Methodspublic Task Invoke(HttpContext context){// Exceptionthrow new Exception();// Returnreturn Task.CompletedTask;} } frameborder0 scrollingno styleborder-width: initial; border-style: none; width: 715px; height: 510px; RequestDelegate 建立Middleware的时候开发人员可以透过建构子所传入的RequestDelegate来参考到Pipeline里的下一个Middleware。透过调用RequestDelegate就可以调用Pipeline里的下一个Middleware的Invoke方法。在下列的范例程序代码里就是透过调用RequestDelegate来调用Pipeline里的下一个Middleware的Invoke方法藉此串接其他Middleware的程序逻辑。 public class HelloWorldMiddleware {// Fieldsprivate readonly RequestDelegate _next;// Constructorspublic HelloWorldMiddleware(RequestDelegate next){_next next;}// Methodspublic async Task Invoke(HttpContext context){// Do Something 01//....// Nextawait _next.Invoke(context);// Do Something 02// ...} } 参考 Middleware - ASP.NET CoreASP.NET Core 的 Middleware - ASP.NET Core 信息分享 相关文章  Middleware的艺术dotnetCore增加MiddleWare的Run,Use Map MapThen四个扩展方法ASP.NET Core提供模块化Middleware组件ASP.NET Core 开发-中间件(Middleware)[ASP.NET Core] Static File Middleware用Middleware给ASP.NET Core Web API添加自己的授权验证 原文地址http://www.cnblogs.com/clark159/p/5974280.html .NET社区新闻深度好文微信中搜索dotNET跨平台或扫描二维码关注 赞赏
http://wiki.neutronadmin.com/news/280941/

相关文章:

  • 微信公众号怎么推广百度seo详解
  • 青岛定制网站设计公司叫任何一个人一个小时做网站
  • 免费发布信息网站网址大全网络系统管理员
  • 娄底建设网站在线网站备份
  • 网站适合用angular做吗做门窗安装用哪些网站找生意
  • 怎么在国外的搜索网站做推广优良的网站邮箱服务器提供商isp
  • 做任务有q币的网站网站开发运营费用
  • 动漫网站设计源代码抖音小程序搭建
  • 制作网站需要什么成本python做网站原理
  • 嘉兴网站排名优化费用wordpress 修改个人资料
  • 农村电商网站建设方案徐州哪里做网站好
  • 网站规划与建设进度网站上内容列表怎么做的
  • 云一网站建设微信免费开发平台
  • 网站内容页模板做网站的公司哪家好
  • 龙湖建设工程有限公司网站牛人网络网站
  • 天津市做网站的公司北京云无限优化
  • 弋阳网站建设制作wordpress网站二次开发
  • 怎样建立网站建设dede网站首页加悬浮广告
  • 网站建设重庆招聘哈尔滨网络公司网站建设
  • 安徽圣力建设集团网站佳木斯做网站公司
  • html做分模块的网站7年级微机课做网站的软件
  • photoshop 做网站logo网站logo设计理念
  • 网站上实用的h5特效十大个人博客网站
  • 临沂网站搜索排名wordpress搬家后图片无法显示
  • 郴州网站制作公司地址网站开发的人李海涛
  • 做动画上传网站赚钱么揭阳网站设计
  • 维护网站一年多少钱logo在线制作软件
  • 公司建设网站怎么做账微信微网站建设平台
  • 网站建设 制作教程 pdf求个网站好人一生平安
  • 建立网站的准备工作南京模板建站哪家好