【原創】cs+html+js+css模式(四):RemoteCallHandler的修改

來源:互聯網
上載者:User

1.         回顧:

在上一篇我們把所用到的RemoteCallHandler詳細的介紹了,包括了它自己內部進行流的竊取,與在訪問時進行的資料解析,讓JS中的函數能與cs進行互動的等知識,對這些知識有了大體的瞭解,基本瞭解了一些。

2.         介紹:

本章還是介紹RemoteCallHandler,為什麼現在還是介紹此類,因為由於我們所在的地區不同,所用的瀏覽器不同,會在我們的requestHandler中產生多餘的字元,會出現gzip的標頭檔,為瞭解決此標頭檔的問題,我們現在就把上一篇的代碼進行修改。

3.         RemoteCallHandler類的修改:

 

原來的代碼

 /*擷取要調用的後台函數名*/
string methodName = request.Headers["CallingMethod"];
/*判斷操作類型名是否為空白*/
if (string.IsNullOrEmpty(typeName)) { throw new MissingCallingTypeException(); }
/*判斷調用的後台函數名是否為空白*/
if (string.IsNullOrEmpty(methodName)) { throw new MissingCallingMethodException(); }

 

 

修改後的代碼

//主要修改位置:此處是用特殊的字元用正則匹配後,直接取後面的字元資訊
Match m = Regex.Match(request.Headers["CallingMethod"].Replace(";",""), @"(?<method>\w+)517MethodEnd");
if (!m.Success){
   LogUtility.TxtLog.WriteTraceLog(string.Format("User:{0}\tAssembly:{1}\tTypeName:{2}\tMethodName:{3}", (HttpContext.Current.Session["LoginStaff"] as Better.Model.MStaffInfo).staff_id, assembly, typeName, request.Headers["CallingMethod"]));
   throw new MissingCallingMethodException(); 
}
string methodName = m.Groups["method"].Value;

 

 基本的修改就只有這裡,那麼我們就再也不害怕requestheader中出現gzip的情況了,下一篇我們會講js中的調用

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.