public void ProcessRequest(HttpContext mycontext) { context = mycontext; //创建 ctrl 对象, 获得业务实体类. DirectoryPageBase ctrl = Activator.CreateInstance(this.CtrlType, context) as DirectoryPageBase; ctrl.context = mycontext; try { //执行方法返回json. string data = ctrl.DoMethod(ctrl, ctrl.DoType); //返回执行的结果. ctrl.context.Response.Write(data); } catch (Exception ex) { string paras = ""; foreach (string key in context.Request.QueryString.Keys) { paras += "@" + key + "=" + context.Request.QueryString[key]; } string err = ""; //返回执行错误的结果. if (ex.InnerException != null) { err = "err@在执行类[" + this.CtrlType.ToString() + "],方法[" + ctrl.DoType + "]错误 \t\n @" + ex.InnerException.Message + " \t\n @技术信息:" + ex.StackTrace + " \t\n相关参数:" + paras; } else { err = "err@在执行类[" + this.CtrlType.ToString() + "],方法[" + ctrl.DoType + "]错误 \t\n @" + ex.Message + " \t\n @技术信息:" + ex.StackTrace + " \t\n相关参数:" + paras; } if (Web.WebUser.No == null) { err = "err@登录时间过长,请重新登录. @其他信息:" + err; } //记录错误日志以方便分析. BP.DA.Log.DebugWriteError(err); ctrl.context.Response.Write(err); } }
public void ProcessRequest(HttpContext mycontext) { context = mycontext; //创建 ctrl 对象, 获得业务实体类. DirectoryPageBase ctrl = Activator.CreateInstance(this.CtrlType, context) as DirectoryPageBase; ctrl.context = mycontext; //让其支持跨域访问. if (!string.IsNullOrEmpty(ctrl.context.Request.Headers["Origin"])) { var allAccess_Control_Allow_Origin = System.Web.Configuration.WebConfigurationManager.AppSettings["Access-Control-Allow-Origin"]; if (!string.IsNullOrEmpty(allAccess_Control_Allow_Origin)) { var origin = ctrl.context.Request.Headers["Origin"]; if (System.Web.Configuration.WebConfigurationManager.AppSettings["Access-Control-Allow-Origin"].Contains(origin)) { ctrl.context.Response.Headers["Access-Control-Allow-Origin"] = origin; ctrl.context.Response.Headers["Access-Control-Allow-Credentials"] = "true"; ctrl.context.Response.Headers["Access-Control-Allow-Headers"] = "x-requested-with,content-type"; } } } try { //执行方法返回json. string data = ctrl.DoMethod(ctrl, ctrl.DoType); //返回执行的结果. ctrl.context.Response.Write(data); } catch (Exception ex) { string paras = ""; foreach (string key in context.Request.QueryString.Keys) { paras += "@" + key + "=" + context.Request.QueryString[key]; } string err = ""; //返回执行错误的结果. if (ex.InnerException != null) { err = "err@在执行类[" + this.CtrlType.ToString() + "],方法[" + ctrl.DoType + "]错误 \t\n @" + ex.InnerException.Message + " \t\n @技术信息:" + ex.StackTrace + " \t\n相关参数:" + paras; } else { err = "err@在执行类[" + this.CtrlType.ToString() + "],方法[" + ctrl.DoType + "]错误 \t\n @" + ex.Message + " \t\n @技术信息:" + ex.StackTrace + " \t\n相关参数:" + paras; } if (Web.WebUser.No == null) { err = "err@登录时间过长,请重新登录. @其他信息:" + err; } //记录错误日志以方便分析. BP.DA.Log.DebugWriteError(err); ctrl.context.Response.Write(err); } }