public void ProcessRequest(HttpContext context) { this.context = context; try { Type t = _ControllerType = this.GetType(); string[] items = QueryTool.GetLocalPath().Trim('/').Split('/'); string methodName = string.Empty; switch (RouteConfig.RouteMode) { case 0: methodName = items[0]; break; case 1: if (items.Length > 1) { methodName = items[1]; } break; case 2: if (items.Length > 2) { methodName = items[2]; } break; } MethodInfo method = InvokeLogic.GetMethod(t, methodName); if (method != null) { _Action = method.Name; BeforeInvoke(method.Name); if (!CancelLoadHtml) { _View = ViewEngine.Create(t.Name, method.Name); } //#if DEBUG // string text = "Invoke " + t.FullName + "." + Action + "(" + Para + ")<hr />"; // if (_View != null) // { // _View.AppendNode(_View.GetList("body")[0], _View.CreateNode("div", text), 0); // } // else // { // System.Web.HttpContext.Current.Response.Write(text); // } //#endif if (!CancelInvoke) { method.Invoke(this, null); if (IsHttpPost) { string name = GetBtnName(); if (!string.IsNullOrEmpty(name)) { MethodInfo postBtnMethod = InvokeLogic.GetMethod(t, name); if (postBtnMethod != null && postBtnMethod.Name != InvokeLogic.Default) { postBtnMethod.Invoke(this, null); } } } if (!CancelInvoke) { EndInvoke(method.Name); } } if (View != null) { context.Response.Write(View.OutXml); } else if (apiResult.Length > 0) { context.Response.Write(apiResult.ToString()); } } } catch (System.Threading.ThreadAbortException) { return; } catch (Exception err) { WriteError(err.Message); context.Response.Write(err.Message); } context.Response.End(); }
public void ProcessRequest(HttpContext context) { this.context = context; try { Type t = _ControllerType = this.GetType(); string[] items = QueryTool.GetLocalPath().Trim('/').Split('/'); string methodName = string.Empty; switch (RouteConfig.RouteMode) { case 0: methodName = items[0]; break; case 1: if (items.Length > 1) { methodName = items[1]; } break; case 2: if (items.Length > 2) { methodName = items[2]; } break; } bool isGoOn = true; //if (InvokeLogic.BeforeInvokeMethod != null) //{ // isGoOn = Convert.ToBoolean(InvokeLogic.BeforeInvokeMethod.Invoke(null, new object[] { this, methodName })); //} //if (isGoOn) //{ char[] attrFlags; MethodInfo method = InvokeLogic.GetMethod(t, methodName, out attrFlags); if (method != null) { if (attrFlags[0] == '1') { #region Invoke CheckToken MethodInfo checkToken = InvokeLogic.GetMethod(t, InvokeLogic.CheckToken); if (checkToken != null && checkToken.Name == InvokeLogic.CheckToken) { isGoOn = Convert.ToBoolean(checkToken.Invoke(this, null)); } else if (InvokeLogic.CheckTokenMethod != null) { isGoOn = Convert.ToBoolean(InvokeLogic.CheckTokenMethod.Invoke(null, new object[] { this, methodName })); } #endregion } if (isGoOn && attrFlags[1] != attrFlags[2])//配置了HttpGet或HttpPost { if (attrFlags[1] == '1' && !IsHttpGet) { isGoOn = false; Write("Only support HttpGet!", false); } else if (attrFlags[2] == '1' && !IsHttpPost) { isGoOn = false; Write("Only support HttpPost!", false); } } if (isGoOn) { #region Method Invoke _Action = method.Name; MethodInfo beforeInvoke = InvokeLogic.GetMethod(t, InvokeLogic.BeforeInvoke); if (beforeInvoke != null && beforeInvoke.Name == InvokeLogic.BeforeInvoke) { isGoOn = Convert.ToBoolean(beforeInvoke.Invoke(this, new object[] { method.Name })); } else if (InvokeLogic.BeforeInvokeMethod != null) { isGoOn = Convert.ToBoolean(InvokeLogic.BeforeInvokeMethod.Invoke(null, new object[] { this, methodName })); } //BeforeInvoke(method.Name); if (!CancelLoadHtml) { _View = ViewEngine.Create(t.Name, method.Name); } if (isGoOn) { method.Invoke(this, GetInvokeParas(method)); if (IsHttpPost) { string name = GetBtnName(); if (!string.IsNullOrEmpty(name)) { MethodInfo postBtnMethod = InvokeLogic.GetMethod(t, name); if (postBtnMethod != null && postBtnMethod.Name != InvokeLogic.Default) { postBtnMethod.Invoke(this, GetInvokeParas(postBtnMethod)); } } } if (isGoOn) { MethodInfo endInvoke = InvokeLogic.GetMethod(t, InvokeLogic.EndInvoke); if (endInvoke != null && endInvoke.Name == InvokeLogic.EndInvoke) { isGoOn = Convert.ToBoolean(endInvoke.Invoke(this, new object[] { method.Name })); } else if (InvokeLogic.EndInvokeMethod != null) { InvokeLogic.EndInvokeMethod.Invoke(null, new object[] { this, methodName }); } // EndInvoke(method.Name); } } #endregion } } //} if (string.IsNullOrEmpty(context.Response.Charset)) { context.Response.Charset = "utf-8"; } if (View != null) { context.Response.Write(View.OutXml); } else if (apiResult.Length > 0) { if (apiResult[0] == '{' && apiResult[apiResult.Length - 1] == '}') { context.Response.ContentType = "application/json"; } context.Response.Write(apiResult.ToString()); } } catch (System.Threading.ThreadAbortException) { return; } catch (Exception err) { string errMssg = err.InnerException != null ? err.InnerException.Message : err.Message; WriteLog(errMssg); context.Response.Write(errMssg); } }
public void ProcessRequest(HttpContext context) { this.context = context; try { Type t = _ControllerType = this.GetType(); #region GetMethodName string[] items = QueryTool.GetLocalPath().Trim('/').Split('/'); string methodName = string.Empty; switch (RouteConfig.RouteMode) { case 0: methodName = items[0]; break; case 1: if (items.Length > 1) { methodName = items[1]; } break; case 2: _Module = items[0]; if (items.Length > 2) { methodName = items[2]; } break; } _Action = methodName; #endregion bool isGoOn = true; AttributeList attrFlags; MethodInfo method = InvokeLogic.GetMethod(t, methodName, out attrFlags); if (method != null) { if (isGoOn)//配置了HttpGet或HttpPost { isGoOn = attrFlags.HasKey(Request.HttpMethod); if (!isGoOn) { Write("Http method not support " + Request.HttpMethod, false); } } if (isGoOn && attrFlags.HasAck)//有[Ack] { #region Validate CheckAck MethodInfo checkAck = InvokeLogic.GetMethod(t, InvokeLogic.Const.CheckAck); if (checkAck != null && checkAck.Name == InvokeLogic.Const.CheckAck) { isGoOn = Convert.ToBoolean(checkAck.Invoke(this, null)); } else if (InvokeLogic.DefaultCheckAck != null) { isGoOn = Convert.ToBoolean(InvokeLogic.DefaultCheckAck.Invoke(null, new object[] { this, methodName })); } #endregion } if (isGoOn && attrFlags.HasToken)//有[Token] { #region Validate CheckToken MethodInfo checkToken = InvokeLogic.GetMethod(t, InvokeLogic.Const.CheckToken); if (checkToken != null && checkToken.Name == InvokeLogic.Const.CheckToken) { isGoOn = Convert.ToBoolean(checkToken.Invoke(this, null)); } else if (InvokeLogic.DefaultCheckToken != null) { isGoOn = Convert.ToBoolean(InvokeLogic.DefaultCheckToken.Invoke(null, new object[] { this, methodName })); } else if (InvokeLogic.AuthCheckToken != null) { isGoOn = Convert.ToBoolean(InvokeLogic.AuthCheckToken.Invoke(null, new object[] { this })); } #endregion } if (isGoOn) { #region Method Invoke #region BeforeInvoke if (InvokeLogic.BeforeInvokeMethod != null)//先调用全局 { isGoOn = Convert.ToBoolean(InvokeLogic.BeforeInvokeMethod.Invoke(null, new object[] { this, methodName })); } if (isGoOn) { MethodInfo beforeInvoke = InvokeLogic.GetMethod(t, InvokeLogic.Const.BeforeInvoke); if (beforeInvoke != null && beforeInvoke.Name == InvokeLogic.Const.BeforeInvoke) { isGoOn = Convert.ToBoolean(beforeInvoke.Invoke(this, new object[] { method.Name })); } } #endregion //BeforeInvoke(method.Name); if (!CancelLoadHtml) { _View = ViewEngine.Create(t.Name, method.Name); if (_View != null) { //追加几个全局标签变量 _View.KeyValue.Add("module", Module.ToLower()); _View.KeyValue.Add("controller", ControllerType.Name.ToLower()); _View.KeyValue.Add("action", Action.ToLower()); _View.KeyValue.Add("para", Para.ToLower()); } } if (isGoOn) { object[] paras; if (GetInvokeParas(method, out paras)) { method.Invoke(this, paras); if (IsHttpPost) { #region Button Invoke string name = GetBtnName(); if (!string.IsNullOrEmpty(name)) { MethodInfo postBtnMethod = InvokeLogic.GetMethod(t, name); if (postBtnMethod != null && postBtnMethod.Name != InvokeLogic.Const.Default) { GetInvokeParas(postBtnMethod, out paras); postBtnMethod.Invoke(this, paras); } } #endregion } if (isGoOn) { #region EndInvoke MethodInfo endInvoke = InvokeLogic.GetMethod(t, InvokeLogic.Const.EndInvoke); if (endInvoke != null && endInvoke.Name == InvokeLogic.Const.EndInvoke) { endInvoke.Invoke(this, new object[] { method.Name }); } if (InvokeLogic.EndInvokeMethod != null) { InvokeLogic.EndInvokeMethod.Invoke(null, new object[] { this, methodName }); } #endregion //if (InvokeLogic.DocRecord != null) //{ // InvokeLogic.DocRecord.Invoke(null, new object[] { this, methodName }); //} } } } #endregion } } if (string.IsNullOrEmpty(context.Response.Charset)) { context.Response.Charset = "utf-8"; } if (View != null) { context.Response.Write(View.OutXml); } else if (apiResult.Length > 0) { string outResult = apiResult.ToString(); if (string.IsNullOrEmpty(context.Response.ContentType)) { context.Response.ContentType = "text/html"; } if (context.Response.ContentType == "text/html") { if (apiResult[0] == '{' && apiResult[apiResult.Length - 1] == '}') { context.Response.ContentType = "application/json"; } else if (outResult.StartsWith("<?xml") && apiResult[apiResult.Length - 1] == '>') { context.Response.ContentType = "application/xml"; } } context.Response.Write(outResult); } } catch (System.Threading.ThreadAbortException) { return; } catch (Exception err) { string errMssg = err.InnerException != null ? err.InnerException.Message : err.Message; WriteLog(errMssg); if (View == null) { errMssg = JsonHelper.OutResult(false, errMssg); } context.Response.Write(errMssg); } }
public void ProcessRequest(HttpContext context) { this.context = context; try { Type t = _ControllerType = this.GetType(); #region GetMethodName string[] items = QueryTool.GetLocalPath().Trim('/').Split('/'); string methodName = string.Empty; switch (RouteConfig.RouteMode) { case 0: methodName = items[0]; break; case 1: if (items.Length > 1) { methodName = items[1]; } break; case 2: _Module = items[0]; if (items.Length > 2) { methodName = items[2]; } break; } _Action = methodName; #endregion bool isGoOn = true; char[] attrFlags; MethodInfo method = InvokeLogic.GetMethod(t, methodName, out attrFlags); if (method != null) { if (attrFlags[0] == '1') { #region Validate CheckToken MethodInfo checkToken = InvokeLogic.GetMethod(t, InvokeLogic.Const.CheckToken); if (checkToken != null && checkToken.Name == InvokeLogic.Const.CheckToken) { isGoOn = Convert.ToBoolean(checkToken.Invoke(this, null)); } else if (InvokeLogic.DefaultCheckToken != null) { isGoOn = Convert.ToBoolean(InvokeLogic.DefaultCheckToken.Invoke(null, new object[] { this, methodName })); } else if (InvokeLogic.AuthCheckToken != null) { isGoOn = Convert.ToBoolean(InvokeLogic.AuthCheckToken.Invoke(null, new object[] { this })); } #endregion } if (isGoOn)//配置了HttpGet或HttpPost { #region Validate Http methods string[] httpMethods = InvokeLogic.HttpMethods; for (int i = 0; i < httpMethods.Length; i++) { if (attrFlags[i + 1] == '1') { isGoOn = false; if (httpMethods[i] == Request.HttpMethod) { isGoOn = true; break; } } } if (!isGoOn) { Write("Http method not support " + Request.HttpMethod, false); } #endregion } if (isGoOn) { #region Method Invoke #region BeforeInvoke MethodInfo beforeInvoke = InvokeLogic.GetMethod(t, InvokeLogic.Const.BeforeInvoke); if (beforeInvoke != null && beforeInvoke.Name == InvokeLogic.Const.BeforeInvoke) { isGoOn = Convert.ToBoolean(beforeInvoke.Invoke(this, new object[] { method.Name })); } else if (InvokeLogic.BeforeInvokeMethod != null) { isGoOn = Convert.ToBoolean(InvokeLogic.BeforeInvokeMethod.Invoke(null, new object[] { this, methodName })); } #endregion //BeforeInvoke(method.Name); if (!CancelLoadHtml) { _View = ViewEngine.Create(t.Name, method.Name); } if (isGoOn) { object[] paras; if (GetInvokeParas(method, out paras)) { method.Invoke(this, paras); if (IsHttpPost) { #region Button Invoke string name = GetBtnName(); if (!string.IsNullOrEmpty(name)) { MethodInfo postBtnMethod = InvokeLogic.GetMethod(t, name); if (postBtnMethod != null && postBtnMethod.Name != InvokeLogic.Const.Default) { GetInvokeParas(postBtnMethod, out paras); postBtnMethod.Invoke(this, paras); } } #endregion } if (isGoOn) { #region EndInvoke MethodInfo endInvoke = InvokeLogic.GetMethod(t, InvokeLogic.Const.EndInvoke); if (endInvoke != null && endInvoke.Name == InvokeLogic.Const.EndInvoke) { isGoOn = Convert.ToBoolean(endInvoke.Invoke(this, new object[] { method.Name })); } else if (InvokeLogic.EndInvokeMethod != null) { InvokeLogic.EndInvokeMethod.Invoke(null, new object[] { this, methodName }); } #endregion if (InvokeLogic.DocRecord != null) { InvokeLogic.DocRecord.Invoke(null, new object[] { this, methodName }); } } } } #endregion } } if (string.IsNullOrEmpty(context.Response.Charset)) { context.Response.Charset = "utf-8"; } if (View != null) { context.Response.Write(View.OutXml); } else if (apiResult.Length > 0) { if (apiResult[0] == '{' && apiResult[apiResult.Length - 1] == '}') { context.Response.ContentType = "application/json"; } context.Response.Write(apiResult.ToString()); } } catch (System.Threading.ThreadAbortException) { return; } catch (Exception err) { string errMssg = err.InnerException != null ? err.InnerException.Message : err.Message; WriteLog(errMssg); if (View == null) { errMssg = JsonHelper.OutResult(false, errMssg); } context.Response.Write(errMssg); } }
public void ProcessRequest(HttpContext context) { this.context = context; try { Type t = _ControllerType = this.GetType(); string[] items = QueryTool.GetLocalPath().Trim('/').Split('/'); string methodName = string.Empty; switch (RouteConfig.RouteMode) { case 0: methodName = items[0]; break; case 1: if (items.Length > 1) { methodName = items[1]; } break; case 2: if (items.Length > 2) { methodName = items[2]; } break; } bool hasTokenAttr = false; MethodInfo method = InvokeLogic.GetMethod(t, methodName, out hasTokenAttr); if (method != null) { bool isGoOn = true; if (hasTokenAttr && InvokeLogic.CheckTokenMethod != null) { //CheckToken isGoOn = Convert.ToBoolean(InvokeLogic.CheckTokenMethod.Invoke(null, new object[] { this, methodName })); } if (isGoOn) { _Action = method.Name; BeforeInvoke(method.Name); if (!CancelLoadHtml) { _View = ViewEngine.Create(t.Name, method.Name); } if (!CancelInvoke) { method.Invoke(this, null); if (IsHttpPost) { string name = GetBtnName(); if (!string.IsNullOrEmpty(name)) { MethodInfo postBtnMethod = InvokeLogic.GetMethod(t, name); if (postBtnMethod != null && postBtnMethod.Name != InvokeLogic.Default) { postBtnMethod.Invoke(this, null); } } } if (!CancelInvoke) { EndInvoke(method.Name); } } } if (View != null) { context.Response.Write(View.OutXml); } else if (apiResult.Length > 0) { context.Response.Write(apiResult.ToString()); } } } catch (System.Threading.ThreadAbortException) { return; } catch (Exception err) { WriteError(err.Message); context.Response.Write(err.Message); } context.Response.End(); }
public void ProcessRequest(HttpContext context) { this.context = context; try { Type t = _ControllerType = this.GetType(); Init(t); bool isGoOn = true; AttributeList attrFlags; MethodInfo method = MethodCollector.GetMethod(t, Action, out attrFlags); if (method != null) { if (isGoOn)//配置了HttpGet或HttpPost { isGoOn = attrFlags.HasKey(Request.HttpMethod); if (!isGoOn) { Write("Http method not support " + Request.HttpMethod, false); } } if (isGoOn && attrFlags.HasAck)//有[Ack] { #region Validate CheckAck MethodInfo checkAck = MethodCollector.GetMethod(t, Const.CheckAck); if (checkAck != null && checkAck.Name == Const.CheckAck) { isGoOn = Convert.ToBoolean(checkAck.Invoke(this, null)); } else if (MethodCollector.DefaultCheckAck != null) { isGoOn = Convert.ToBoolean(MethodCollector.DefaultCheckAck.Invoke(null, new object[] { this, Action })); } if (!isGoOn) { Write("Check AckAttribute is illegal.", false); } #endregion } if (isGoOn && attrFlags.HasMicroService)//有[MicroService] { #region Validate CheckMicroService 【如果开启全局,即需要调整授权机制,则原有局部机制失效。】 if (MethodCollector.DefaultCheckMicroService != null) { isGoOn = Convert.ToBoolean(MethodCollector.DefaultCheckMicroService.Invoke(null, new object[] { this, Action })); } else { MethodInfo checkMicroService = MethodCollector.GetMethod(t, Const.CheckMicroService); if (checkMicroService != null && checkMicroService.Name == Const.CheckMicroService) { isGoOn = Convert.ToBoolean(checkMicroService.Invoke(this, null)); } } if (!isGoOn) { Write("Check MicroServiceAttribute is illegal.", false); } #endregion } if (isGoOn && attrFlags.HasToken)//有[Token] { #region Validate CheckToken MethodInfo checkToken = MethodCollector.GetMethod(t, Const.CheckToken); if (checkToken != null && checkToken.Name == Const.CheckToken) { isGoOn = Convert.ToBoolean(checkToken.Invoke(this, null)); } else if (MethodCollector.DefaultCheckToken != null) { isGoOn = Convert.ToBoolean(MethodCollector.DefaultCheckToken.Invoke(null, new object[] { this, Action })); } else if (MethodCollector.AuthCheckToken != null) { isGoOn = Convert.ToBoolean(MethodCollector.AuthCheckToken.Invoke(null, new object[] { this })); } if (!isGoOn) { Write("Check TokenAttribute is illegal.", false); } #endregion } if (isGoOn) { #region Method Invoke #region BeforeInvoke if (MethodCollector.BeforeInvokeMethod != null)//先调用全局 { isGoOn = Convert.ToBoolean(MethodCollector.BeforeInvokeMethod.Invoke(null, new object[] { this, Action })); } if (isGoOn) { MethodInfo beforeInvoke = MethodCollector.GetMethod(t, Const.BeforeInvoke); if (beforeInvoke != null && beforeInvoke.Name == Const.BeforeInvoke) { isGoOn = Convert.ToBoolean(beforeInvoke.Invoke(this, new object[] { method.Name })); } } #endregion //BeforeInvoke(method.Name); if (!CancelLoadHtml) { _View = ViewEngine.Create(t.Name, method.Name); if (_View != null) { //追加几个全局标签变量 _View.KeyValue.Add("module", Module.ToLower()); _View.KeyValue.Add("controller", _ControllerName); _View.KeyValue.Add("action", Action.ToLower()); _View.KeyValue.Add("para", Para.ToLower()); _View.KeyValue.Add("httphost", Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Length - Request.Url.PathAndQuery.Length)); } } if (isGoOn) { object[] paras; if (GetInvokeParas(method, out paras)) { method.Invoke(this, paras); if (IsHttpPost && _View != null) { #region Button Invoke string name = GetBtnName(); if (!string.IsNullOrEmpty(name)) { MethodInfo postBtnMethod = MethodCollector.GetMethod(t, name); if (postBtnMethod != null && postBtnMethod.Name != Const.Default) { GetInvokeParas(postBtnMethod, out paras); postBtnMethod.Invoke(this, paras); } } #endregion } if (isGoOn) { #region EndInvoke MethodInfo endInvoke = MethodCollector.GetMethod(t, Const.EndInvoke); if (endInvoke != null && endInvoke.Name == Const.EndInvoke) { endInvoke.Invoke(this, new object[] { method.Name }); } if (MethodCollector.EndInvokeMethod != null) { MethodCollector.EndInvokeMethod.Invoke(null, new object[] { this, Action }); } #endregion //if (InvokeLogic.DocRecord != null) //{ // InvokeLogic.DocRecord.Invoke(null, new object[] { this, methodName }); //} } } } #endregion } } else { //检测全局Default方法 MethodInfo globalDefault = MethodCollector.GlobalDefault; if (globalDefault != null) { object o = Activator.CreateInstance(globalDefault.DeclaringType);//实例化 globalDefault.DeclaringType.GetMethod("ProcessRequest").Invoke(o, new object[] { context }); return; } } if (string.IsNullOrEmpty(context.Response.Charset)) { context.Response.Charset = "utf-8"; } if (View != null) { context.Response.Write(View.OutXml); View = null; } else if (apiResult.Length > 0) { string outResult = apiResult.ToString(); if (string.IsNullOrEmpty(context.Response.ContentType)) { context.Response.ContentType = "text/html;charset=" + context.Response.Charset; } if (context.Response.ContentType.StartsWith("text/html")) { if (apiResult[0] == '{' && apiResult[apiResult.Length - 1] == '}') { context.Response.ContentType = "application/json;charset=" + context.Response.Charset; } else if (outResult.StartsWith("<?xml") && apiResult[apiResult.Length - 1] == '>') { context.Response.ContentType = "application/xml;charset=" + context.Response.Charset; } } context.Response.Write(outResult); outResult = null; apiResult = null; } } catch (System.Threading.ThreadAbortException) { return; } catch (Exception err) { StringBuilder sb = new StringBuilder(); string errMsg = Log.GetExceptionMessage(err); sb.AppendLine(errMsg); if (err.StackTrace != null) { sb.AppendLine(err.StackTrace); } if (Request.Headers.Count > 0) { sb.AppendLine("\n-----------Headers-----------"); foreach (string key in Request.Headers.AllKeys) { sb.AppendLine(key + " : " + Request.Headers[key]); } } if (Request.Form.Count > 0) { sb.AppendLine("-----------Forms-----------"); foreach (string key in Request.Form.AllKeys) { sb.AppendLine(key + " : " + Request.Form[key]); } } WriteLog("【Taurus.Core.Controller】:" + sb.ToString()); if (View == null) { errMsg = JsonHelper.OutResult(false, errMsg); } context.Response.Write(errMsg); } }
public void ProcessRequest(HttpContext context) { this.context = context; try { Type t = _ControllerType = this.GetType(); string[] items = QueryTool.GetLocalPath().Trim('/').Split('/'); string methodName = string.Empty; switch (RouteConfig.RouteMode) { case 0: methodName = items[0]; break; case 1: if (items.Length > 1) { methodName = items[1]; } break; case 2: if (items.Length > 2) { methodName = items[2]; } break; } bool isGoOn = true; if (InvokeLogic.BeforeInvokeMethod != null) { isGoOn = Convert.ToBoolean(InvokeLogic.BeforeInvokeMethod.Invoke(null, new object[] { this, methodName })); } if (isGoOn) { char[] attrFlags; MethodInfo method = InvokeLogic.GetMethod(t, methodName, out attrFlags); if (method != null) { if (attrFlags[0] == '1') { #region CheckToken MethodInfo checkToken = InvokeLogic.GetMethod(t, InvokeLogic.CheckToken); if (checkToken != null && checkToken.Name == InvokeLogic.CheckToken) { isGoOn = Convert.ToBoolean(checkToken.Invoke(this, null)); } else if (InvokeLogic.CheckTokenMethod != null) { isGoOn = Convert.ToBoolean(InvokeLogic.CheckTokenMethod.Invoke(null, new object[] { this, methodName })); } #endregion } if (isGoOn && attrFlags[1] != attrFlags[2])//配置了HttpGet或HttpPost { if (attrFlags[1] == '1' && !IsHttpGet) { isGoOn = false; Write("Only support HttpGet!", false); } else if (attrFlags[2] == '1' && !IsHttpPost) { isGoOn = false; Write("Only support HttpPost!", false); } } if (isGoOn) { #region Method Invoke _Action = method.Name; BeforeInvoke(method.Name); if (!CancelLoadHtml) { _View = ViewEngine.Create(t.Name, method.Name); } if (!CancelInvoke) { method.Invoke(this, null); if (IsHttpPost) { string name = GetBtnName(); if (!string.IsNullOrEmpty(name)) { MethodInfo postBtnMethod = InvokeLogic.GetMethod(t, name); if (postBtnMethod != null && postBtnMethod.Name != InvokeLogic.Default) { postBtnMethod.Invoke(this, null); } } } if (!CancelInvoke) { EndInvoke(method.Name); } } #endregion } } } if (View != null) { context.Response.Write(View.OutXml); } else if (apiResult.Length > 0) { context.Response.Write(apiResult.ToString()); } } catch (System.Threading.ThreadAbortException) { return; } catch (Exception err) { string errorMsg = string.Empty; if (err.InnerException != null) { errorMsg = string.Format("异常信息:{0}" + Environment.NewLine + "堆栈信息:{1}。" , err.InnerException.Message , err.InnerException.StackTrace); } else { errorMsg = string.Format("异常信息:{0}" + Environment.NewLine + "堆栈信息:{1}。" , err.Message, err.StackTrace); } WriteError(errorMsg); if (AppSettings.IsDevMode)//开发者模式 { context.Response.Write(errorMsg); } else { context.Response.Write(err.Message); } } if (string.IsNullOrEmpty(context.Response.Charset)) { context.Response.Charset = "utf-8"; } }