主頁 > .NET開發 > ASP.NET管道處理模型(二)

ASP.NET管道處理模型(二)

2021-10-11 06:07:59 .NET開發

從上一章中我們知道Http的任何一個請求最終一定是由某一個具體的HttpHandler來處理的,不管是成功還是失敗

而具體是由哪一個HttpHandler來處理,則是由我們的組態檔來指定映射關系:后綴名與處理程式的關系(IHttpHandler---IHttpHandlerFactory)

但是我們都知道在MVC中訪問時并沒有使用什么后綴,而是使用路由去匹配,那這又是怎么回事呢?接下來我們就來談談這件事,

首先我們來看下MVC中到底是由哪個HttpHandler來處理的:

Home 控制器:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewBag.CurrentHandler = base.HttpContext.CurrentHandler;
        return View();
    }
}

對應的 Index 視圖:

@{
    ViewBag.Title = "Home Page";
}

<h2>
    This is Home/Index View
</h2>
<h1>
   @(ViewBag.CurrentHandler)
</h1>
<hr />

看看此時 HttpContext.CurrentHandler 的輸出結果:

可以看到MVC中使用的HttpHandler是叫【System.Web.Mvc.MvcHandler】,

所謂MVC框架,其實就是在Asp.Net管道上擴展的,在PostResolveRequestCache事件擴展了UrlRoutingModule,

會在任何請求進來后,先進行路由匹配,如果匹配上了就指定HttpHandler為MvcHandler,沒有匹配上就還是走原始流程,

那為什么要選擇在PostResolveRequestCache這個事件進行擴展呢?

從圖中我們可以得知在PostResolveRequestCache事件之后就要指定請求該如何處理了,因此我們也就能理解為什么要選擇在PostResolveRequestCache這個事件上面進行MVC擴展了,

下面我們通過反編譯工具來看一下 UrlRoutingModule 這個類:

using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Web.Security;

namespace System.Web.Routing
{
    [TypeForwardedFrom("System.Web.Routing, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")]
    public class UrlRoutingModule : IHttpModule
    {
        private static readonly object _contextKey = new object();

        private static readonly object _requestDataKey = new object();

        private RouteCollection _routeCollection;

        public RouteCollection RouteCollection
        {
            get
            {
                if (this._routeCollection == null)
                {
                    this._routeCollection = RouteTable.Routes;
                }
                return this._routeCollection;
            }
            set
            {
                this._routeCollection = value;
            }
        }

        protected virtual void Dispose()
        {
        }

        protected virtual void Init(HttpApplication application)
        {
            if (application.Context.Items[UrlRoutingModule._contextKey] != null)
            {
                return;
            }
            application.Context.Items[UrlRoutingModule._contextKey] = UrlRoutingModule._contextKey;
            application.PostResolveRequestCache += new EventHandler(this.OnApplicationPostResolveRequestCache);
        }

        private void OnApplicationPostResolveRequestCache(object sender, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContextBase context = new HttpContextWrapper(httpApplication.Context);
            this.PostResolveRequestCache(context);
        }

        [Obsolete("This method is obsolete. Override the Init method to use the PostMapRequestHandler event.")]
        public virtual void PostMapRequestHandler(HttpContextBase context)
        {
        }

        public virtual void PostResolveRequestCache(HttpContextBase context)
        {
            RouteData routeData = this.RouteCollection.GetRouteData(context);
            if (routeData =https://www.cnblogs.com/xyh9039/p/= null)
            {
                return;
            }
            IRouteHandler routeHandler = routeData.RouteHandler;
            if (routeHandler == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.GetString("UrlRoutingModule_NoRouteHandler"), new object[0]));
            }
            if (routeHandler is StopRoutingHandler)
            {
                return;
            }
            RequestContext requestContext = new RequestContext(context, routeData);
            context.Request.RequestContext = requestContext;
            IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);
            if (httpHandler == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, SR.GetString("UrlRoutingModule_NoHttpHandler"), new object[]
                {
                    routeHandler.GetType()
                }));
            }
            if (!(httpHandler is UrlAuthFailureHandler))
            {
                context.RemapHandler(httpHandler);
                return;
            }
            if (FormsAuthenticationModule.FormsAuthRequired)
            {
                UrlAuthorizationModule.ReportUrlAuthorizationFailure(HttpContext.Current, this);
                return;
            }
            throw new HttpException(401, SR.GetString("Assess_Denied_Description3"));
        }

        void IHttpModule.Dispose()
        {
            this.Dispose();
        }

        void IHttpModule.Init(HttpApplication application)
        {
            this.Init(application);
        }
    }
}

從上面的原始碼中我們大概可以知道:

1、首先它是根據HttpContextBase從RouteCollection中獲取RouteData,判斷RouteData是否為空(也就是判斷路由是否匹配上),如果路由匹配失敗則還是走原始的Asp.Net流程,否則就走MVC流程,從中可以知道MVC和WebForm是可以共存的,也能解釋為啥指定后綴請求需要路由的忽略,

2、經過路由匹配得到RouteData,然后使用RouteData獲取RouteHandler,接著再根據RouteHandler獲取HttpHandler,最后將HttpContextBase背景關系中的HttpHandler指定為這個HttpHandler,

3、看完下文你就會知道從RouteCollection中獲取的這個RouteHandler其實就是MvcRouteHandler,而最侄訓取到的這個HttpHandler其實就是MvcHandler

我們繼續通過反編譯工具 沿著 this.RouteCollection.GetRouteData(context) 往里找:

// System.Web.Routing.RouteCollection
public RouteData GetRouteData(HttpContextBase httpContext)
{
    if (httpContext == null)
    {
        throw new ArgumentNullException("httpContext");
    }
    if (httpContext.Request == null)
    {
        throw new ArgumentException(SR.GetString("RouteTable_ContextMissingRequest"), "httpContext");
    }
    if (base.Count == 0)
    {
        return null;
    }
    bool flag = false;
    bool flag2 = false;
    if (!this.RouteExistingFiles)
    {
        flag = this.IsRouteToExistingFile(httpContext);
        flag2 = true;
        if (flag)
        {
            return null;
        }
    }
    using (this.GetReadLock())
    {
        foreach (RouteBase current in this)
        {
            RouteData routeData = current.GetRouteData(httpContext);
            if (routeData != null)
            {
                RouteData result;
                if (!current.RouteExistingFiles)
                {
                    if (!flag2)
                    {
                        flag = this.IsRouteToExistingFile(httpContext);
                    }
                    if (flag)
                    {
                        result = null;
                        return result;
                    }
                }
                result = routeData;
                return result;
            }
        }
    }
    return null;
}

從此處我們可以發現,它是按照添加順序進行匹配的,第一個吻合的就直接回傳,后面的無效,

說到RouteCollection其實我們并不陌生,在路由配置的時候就有用到它:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace AspNetPipeline
{
    /// <summary>
    /// 路由是按照注冊順序進行匹配,遇到第一個吻合的就結束匹配,每個請求只會被一個路由匹配上,
    /// </summary>
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            //忽略路由  正則運算式  {resource}表示變數   a.axd/xxxx   resource=a   pathInfo=xxxx
            //.axd是歷史原因,最開始都是WebForm,請求都是.aspx后綴,IIS根據后綴轉發請求;
            //MVC出現了,沒有后綴,IIS6以及更早版本,打了個補丁,把MVC的請求加上個.axd的后綴,然后這種都轉發到網站
            //新版本的IIS已經不需要了,遇到了就直接忽略,還是走原始流程
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //該行框架自帶的

            //.log后綴的請求忽略掉,不走MVC流程,而是用我們自定義的CustomHttpHandler處理器來處理
            routes.IgnoreRoute("{resource}.log/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

我們將游標移動到MapRoute這個方法,然后按F12查看原始碼,可以發現它是來自 RouteCollectionExtensions 這個擴展類,如下所示:

我們通過反編譯工具找到這個類:

我們重點關注其中的MapRoute方法:

/// <summary>Maps the specified URL route and sets default route values, constraints, and namespaces.</summary>
/// <returns>A reference to the mapped route.</returns>
/// <param name="routes">A collection of routes for the application.</param>
/// <param name="name">The name of the route to map.</param>
/// <param name="url">The URL pattern for the route.</param>
/// <param name="defaults">An object that contains default route values.</param>
/// <param name="constraints">A set of expressions that specify values for the <paramref name="url" /> parameter.</param>
/// <param name="namespaces">A set of namespaces for the application.</param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="routes" /> or <paramref name="url" /> parameter is null.</exception>
public static Route MapRoute(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces)
{
    if (routes == null)
    {
        throw new ArgumentNullException("routes");
    }
    if (url == null)
    {
        throw new ArgumentNullException("url");
    }
    Route route = new Route(url, new MvcRouteHandler())
    {
        Defaults = RouteCollectionExtensions.CreateRouteValueDictionaryUncached(defaults),
        Constraints = RouteCollectionExtensions.CreateRouteValueDictionaryUncached(constraints),
        DataTokens = new RouteValueDictionary()
    };
    ConstraintValidation.Validate(route);
    if (namespaces != null && namespaces.Length != 0)
    {
        route.DataTokens["Namespaces"] = namespaces;
    }
    routes.Add(name, route);
    return route;
}

private static RouteValueDictionary CreateRouteValueDictionaryUncached(object values)
{
    IDictionary<string, object> dictionary = values as IDictionary<string, object>;
    if (dictionary != null)
    {
        return new RouteValueDictionary(dictionary);
    }
    return TypeHelper.ObjectToDictionaryUncached(values);
}

可以看到RouteCollection字典容器的key就是路由配置中的name,這也就解釋了路由配置中的name為啥需要唯一,另外RouteCollection字典容器的value存的是Route物件(正則規則 + MvcRouteHandler + 其它路由配置資訊),

我們繼續通過反編譯工具找到 MvcRouteHandler,如下所示:

using System;
using System.Web.Mvc.Properties;
using System.Web.Routing;
using System.Web.SessionState;

namespace System.Web.Mvc
{
    /// <summary>Creates an object that implements the IHttpHandler interface and passes the request context to it.</summary>
    public class MvcRouteHandler : IRouteHandler
    {
        private IControllerFactory _controllerFactory;

        /// <summary>Initializes a new instance of the <see cref="T:System.Web.Mvc.MvcRouteHandler" /> class.</summary>
        public MvcRouteHandler()
        {
        }

        /// <summary>Initializes a new instance of the <see cref="T:System.Web.Mvc.MvcRouteHandler" /> class using the specified factory controller object.</summary>
        /// <param name="controllerFactory">The controller factory.</param>
        public MvcRouteHandler(IControllerFactory controllerFactory)
        {
            this._controllerFactory = controllerFactory;
        }

        /// <summary>Returns the HTTP handler by using the specified HTTP context.</summary>
        /// <returns>The HTTP handler.</returns>
        /// <param name="requestContext">The request context.</param>
        protected virtual IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            requestContext.HttpContext.SetSessionStateBehavior(this.GetSessionStateBehavior(requestContext));
            return new MvcHandler(requestContext);
        }

        /// <summary>Returns the session behavior.</summary>
        /// <returns>The session behavior.</returns>
        /// <param name="requestContext">The request context.</param>
        protected virtual SessionStateBehavior GetSessionStateBehavior(RequestContext requestContext)
        {
            string text = (string)requestContext.RouteData.Values["controller"];
            if (string.IsNullOrWhiteSpace(text))
            {
                throw new InvalidOperationException(MvcResources.MvcRouteHandler_RouteValuesHasNoController);
            }
            return (this._controllerFactory ?? ControllerBuilder.Current.GetControllerFactory()).GetControllerSessionBehavior(requestContext, text);
        }

        /// <summary>Returns the HTTP handler by using the specified request context.</summary>
        /// <returns>The HTTP handler.</returns>
        /// <param name="requestContext">The request context.</param>
        IHttpHandler IRouteHandler.GetHttpHandler(RequestContext requestContext)
        {
            return this.GetHttpHandler(requestContext);
        }
    }
}

找到其中關鍵方法:

可以發現這個方法的回傳值是固定寫死的,就是回傳MvcHandler的一個實體,由此我們知道從RouteCollection中獲取的HttpHandler其實就是MvcHandler,

至此,我們對MVC的處理流程應該就有個大概認識了,下面我們通過一張圖來總結一下MVC的處理流程:

既然原理我們都知道了,那下面我們就可以去做一些有用的擴展,

例如:擴展我們的路由,

從上文中我們知道,路由配置其實就是將Route物件添加到RouteCollection字典中,而從反編譯工具中我們可以得知Route的基類是RouteBase:

那下面我們就來自定義一個Route:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace AspNetPipeline.RouteExtend
{
    /// <summary>
    /// 自定義路由
    /// </summary>
    public class CustomRoute : RouteBase
    {
        /// <summary>
        /// 如果是 Chrome/74.0.3729.169 版本,允許正常訪問,否則跳轉提示頁
        /// </summary>
        /// <param name="httpContext"></param>
        /// <returns></returns>
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            //httpContext.Request.Url.AbsoluteUri
            if (httpContext.Request.UserAgent.Contains("Chrome/74.0.3729.169"))
            {
                return null; //繼續后面的
            }
            else
            {
                RouteData routeData = new RouteData(this, new MvcRouteHandler()); //還是走MVC流程
                routeData.Values.Add("controller", "home");
                routeData.Values.Add("action", "refuse");
                return routeData; //中斷路由匹配
            }
        }

        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
        {
            return null;
        }
    }
}

然后將其添加到RouteCollection字典中:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

using AspNetPipeline.RouteExtend;

namespace AspNetPipeline
{
    /// <summary>
    /// 路由是按照注冊順序進行匹配,遇到第一個吻合的就結束匹配,每個請求只會被一個路由匹配上,
    /// </summary>
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            //忽略路由  正則運算式  {resource}表示變數   a.axd/xxxx   resource=a   pathInfo=xxxx
            //.axd是歷史原因,最開始都是WebForm,請求都是.aspx后綴,IIS根據后綴轉發請求;
            //MVC出現了,沒有后綴,IIS6以及更早版本,打了個補丁,把MVC的請求加上個.axd的后綴,然后這種都轉發到網站
            //新版本的IIS已經不需要了,遇到了就直接忽略,還是走原始流程
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //該行框架自帶的

            //.log后綴的請求忽略掉,不走MVC流程,而是用我們自定義的CustomHttpHandler處理器來處理
            routes.IgnoreRoute("{resource}.log/{*pathInfo}");

            routes.Add("chrome", new CustomRoute());

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

最后我們來訪問一下 /home/index 頁面,運行結果如下所示:

仔細觀察后你會發現我們訪問的是 /home/index 頁面,但是此時卻輸出了 /home/refuse 頁面,說明我們的路由擴展成功了,

除了去擴展Route,此外我們也可以去擴展MvcRouteHandler,如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

using AspNetPipeline.Pipeline;

namespace AspNetPipeline.RouteExtend
{
    /// <summary>
    /// 自定義MvcRouteHandler
    /// </summary>
    public class CustomMvcRouteHandler : MvcRouteHandler
    {
        protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            //requestContext.HttpContext.SetSessionStateBehavior(this.GetSessionStateBehavior(requestContext));
            //return new MvcHandler(requestContext);

            return new CustomHttpHandler(); //將MvcHandler替換成自定義的HttpHandler
        }
    }
}

同樣的,我們將其添加到RouteCollection字典中:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

using AspNetPipeline.RouteExtend;

namespace AspNetPipeline
{
    /// <summary>
    /// 路由是按照注冊順序進行匹配,遇到第一個吻合的就結束匹配,每個請求只會被一個路由匹配上,
    /// </summary>
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            //忽略路由  正則運算式  {resource}表示變數   a.axd/xxxx   resource=a   pathInfo=xxxx
            //.axd是歷史原因,最開始都是WebForm,請求都是.aspx后綴,IIS根據后綴轉發請求;
            //MVC出現了,沒有后綴,IIS6以及更早版本,打了個補丁,把MVC的請求加上個.axd的后綴,然后這種都轉發到網站
            //新版本的IIS已經不需要了,遇到了就直接忽略,還是走原始流程
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //該行框架自帶的

            //.log后綴的請求忽略掉,不走MVC流程,而是用我們自定義的CustomHttpHandler處理器來處理
            routes.IgnoreRoute("{resource}.log/{*pathInfo}");

            routes.Add("config", new Route("log/{*pathInfo}", new CustomMvcRouteHandler()));
            routes.Add("chrome", new CustomRoute());

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

最后我們來訪問下 /log/a 運行結果如下所示:

右鍵查看網頁源代碼:

可以發現輸出了我們想要的東西,說明我們的MvcRouteHandler擴展成功了,

小結:

1、擴展自己的Route,寫入RouteCollection,可以自定義規則完成路由,

2、擴展HttpHandle,就可以為所欲為,跳出MVC框架,

至此本文就全部介紹完了,如果覺得對您有所啟發請記得點個贊哦!!!  

 

Demo原始碼:

鏈接:https://pan.baidu.com/s/1Rb4uq0yB_iB3VsonwiCFKw 
提取碼:68r6

此文由博主精心撰寫轉載請保留此原文鏈接:https://www.cnblogs.com/xyh9039/p/15216683.html

著作權宣告:如有雷同純屬巧合,如有侵權請及時聯系本人修改,謝謝!!!

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/308032.html

標籤:ASP.NET

上一篇:ASP.NET管道處理模型(一)

下一篇:10分鐘學會VS NuGet包私有化部署

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • WebAPI簡介

    Web體系結構: 有三個核心:資源(resource),URL(統一資源識別符號)和表示 他們的關系是這樣的:一個資源由一個URL進行標識,HTTP客戶端使用URL定位資源,表示是從資源回傳資料,媒體型別是資源回傳的資料格式。 接下來我們說下HTTP. HTTP協議的系統是一種無狀態的方式,使用請求/ ......

    uj5u.com 2020-09-09 22:07:47 more
  • asp.net core 3.1 入口:Program.cs中的Main函式

    本文分析Program.cs 中Main()函式中代碼的運行順序分析asp.net core程式的啟動,重點不是剖析原始碼,而是理清程式開始時執行的順序。到呼叫了哪些實體,哪些法方。asp.net core 3.1 的程式入口在專案Program.cs檔案里,如下。ususing System; us ......

    uj5u.com 2020-09-09 22:07:49 more
  • asp.net網站作為websocket服務端的應用該如何寫

    最近被websocket的一個問題困擾了很久,有一個需求是在web網站中搭建websocket服務。客戶端通過網頁與服務器建立連接,然后服務器根據ip給客戶端網頁發送資訊。 其實,這個需求并不難,只是剛開始對websocket的內容不太了解。上網搜索了一下,有通過asp.net core 實作的、有 ......

    uj5u.com 2020-09-09 22:08:02 more
  • ASP.NET 開源匯入匯出庫Magicodes.IE Docker中使用

    Magicodes.IE在Docker中使用 更新歷史 2019.02.13 【Nuget】版本更新到2.0.2 【匯入】修復單列匯入的Bug,單元測驗“OneColumnImporter_Test”。問題見(https://github.com/dotnetcore/Magicodes.IE/is ......

    uj5u.com 2020-09-09 22:08:05 more
  • 在webform中使用ajax

    如果你用過Asp.net webform, 說明你也算是.NET 開發的老兵了。WEBform應該是2011 2013左右,當時還用visual studio 2005、 visual studio 2008。后來基本都用的是MVC。 如果是新開發的專案,估計沒人會用webform技術。但是有些舊版 ......

    uj5u.com 2020-09-09 22:08:50 more
  • iis添加asp.net網站,訪問提示:由于擴展配置問題而無法提供您請求的

    今天在iis服務器配置asp.net網站,遇到一個問題,記錄一下: 問題:由于擴展配置問題而無法提供您請求的頁面。如果該頁面是腳本,請添加處理程式。如果應下載檔案,請添加 MIME 映射。 WindowServer2012服務器,添加角色安裝完.netframework和iis之后,運行aspx頁面 ......

    uj5u.com 2020-09-09 22:10:00 more
  • WebAPI-處理架構

    帶著問題去思考,大家好! 問題1:HTTP請求和回傳相應的HTTP回應資訊之間發生了什么? 1:首先是最底層,托管層,位于WebAPI和底層HTTP堆疊之間 2:其次是 訊息處理程式管道層,這里比如日志和快取。OWIN的參考是將訊息處理程式管道的一些功能下移到堆疊下端的OWIN中間件了。 3:控制器處理 ......

    uj5u.com 2020-09-09 22:11:13 more
  • 微信門戶開發框架-使用指導說明書

    微信門戶應用管理系統,采用基于 MVC + Bootstrap + Ajax + Enterprise Library的技術路線,界面層采用Boostrap + Metronic組合的前端框架,資料訪問層支持Oracle、SQLServer、MySQL、PostgreSQL等資料庫。框架以MVC5,... ......

    uj5u.com 2020-09-09 22:15:18 more
  • WebAPI-HTTP編程模型

    帶著問題去思考,大家好!它是什么?它包含什么?它能干什么? 訊息 HTTP編程模型的核心就是訊息抽象,表示為:HttPRequestMessage,HttpResponseMessage.用于客戶端和服務端之間交換請求和回應訊息。 HttpMethod類包含了一組靜態屬性: private stat ......

    uj5u.com 2020-09-09 22:15:23 more
  • 部署WebApi隨筆

    一、跨域 NuGet參考Microsoft.AspNet.WebApi.Cors WebApiConfig.cs中配置: // Web API 配置和服務 config.EnableCors(new EnableCorsAttribute("*", "*", "*")); 二、清除默認回傳XML格式 ......

    uj5u.com 2020-09-09 22:15:48 more
最新发布
  • C#多執行緒學習(二) 如何操縱一個執行緒

    <a href="https://www.cnblogs.com/x-zhi/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2943582/20220801082530.png" alt="" /></...

    uj5u.com 2023-04-19 09:17:20 more
  • C#多執行緒學習(二) 如何操縱一個執行緒

    C#多執行緒學習(二) 如何操縱一個執行緒 執行緒學習第一篇:C#多執行緒學習(一) 多執行緒的相關概念 下面我們就動手來創建一個執行緒,使用Thread類創建執行緒時,只需提供執行緒入口即可。(執行緒入口使程式知道該讓這個執行緒干什么事) 在C#中,執行緒入口是通過ThreadStart代理(delegate)來提供的 ......

    uj5u.com 2023-04-19 09:16:49 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    <a href="https://www.cnblogs.com/huangxincheng/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/214741/20200614104537.png" alt="" /&g...

    uj5u.com 2023-04-18 08:39:04 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    一:背景 1. 講故事 前段時間協助訓練營里的一位朋友分析了一個程式卡死的問題,回過頭來看這個案例比較經典,這篇稍微整理一下供后來者少踩坑吧。 二:WinDbg 分析 1. 為什么會卡死 因為是表單程式,理所當然就是看主執行緒此時正在做什么? 可以用 ~0s ; k 看一下便知。 0:000> k # ......

    uj5u.com 2023-04-18 08:33:10 more
  • SignalR, No Connection with that ID,IIS

    <a href="https://www.cnblogs.com/smartstar/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/u36196.jpg" alt="" /></a>...

    uj5u.com 2023-03-30 17:21:52 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:15:33 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:13:31 more
  • C#遍歷指定檔案夾中所有檔案的3種方法

    <a href="https://www.cnblogs.com/xbhp/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/957602/20230310105611.png" alt="" /></a&...

    uj5u.com 2023-03-27 14:46:55 more
  • C#/VB.NET:如何將PDF轉為PDF/A

    <a href="https://www.cnblogs.com/Carina-baby/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2859233/20220427162558.png" alt="" />...

    uj5u.com 2023-03-27 14:46:35 more
  • 武裝你的WEBAPI-OData聚合查詢

    <a href="https://www.cnblogs.com/podolski/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/616093/20140323000327.png" alt="" /><...

    uj5u.com 2023-03-27 14:46:16 more