Exemple #1
0
        public void ProcessRequest(HttpContext context)
        {
            System.Runtime.Remoting.Messaging.CallContext.HostContext = context;
            Stopwatch stopwatch = new Stopwatch();

            try
            {
                stopwatch.Start();

                BeeDataAdapter routeData = GetRouteData(context);

                string controllerName = routeData[Constants.BeeControllerName] as string;
                string actionName     = routeData[Constants.BeeActionName] as string;


                HttpContext httpContext = context;
                //this.httpContext = context;
                BeeDataAdapter dataAdapter = new BeeDataAdapter(routeData);

                NameValueCollection formParams = httpContext.Request.Form;
                foreach (string key in formParams.Keys)
                {
                    if (!string.IsNullOrEmpty(key))
                    {
                        dataAdapter.Add(key.ToLower(), StringUtil.HtmlEncode(formParams[key]));
                    }
                }

                formParams = httpContext.Request.QueryString;
                foreach (string key in formParams.Keys)
                {
                    if (!string.IsNullOrEmpty(key))
                    {
                        dataAdapter.Add(key.ToLower(), StringUtil.HtmlEncode(formParams[key]));
                    }
                }
                // 解析inputstream
                string json = new StreamReader(httpContext.Request.InputStream).ReadToEnd();
                if (!string.IsNullOrEmpty(json) && json.StartsWith("{"))
                {
                    var jObject = Newtonsoft.Json.Linq.JObject.Parse(json);
                    foreach (var item in jObject)
                    {
                        dataAdapter.Add(item.Key, item.Value);
                    }
                }

                if (LogRequestFlag)
                {
                    BeeDataAdapter cookieData = new BeeDataAdapter();
                    foreach (string key in context.Request.Cookies.AllKeys)
                    {
                        cookieData.Add(key, context.Request.Cookies[key].Value);
                    }

                    Logger.Debug(@"
cookie:{0}
Request:{1}".FormatWith(cookieData.ToString(), dataAdapter.ToString()));
                }

                ActionExecutingArgs args = new ActionExecutingArgs(controllerName, actionName, dataAdapter);
                ActionExecuting(args); // 提供拦截通道
                if (args.Result != ActionExecutingResult.OK)
                {
                    BeeMvcResult mvcResult = new BeeMvcResult();
                    mvcResult.code = 400;
                    if (args.Code > 0)
                    {
                        mvcResult.code = args.Code;
                    }
                    mvcResult.msg = args.Message;

                    WriteMvcResult(httpContext, mvcResult);
                    return;
                }

                InnerExecuteAction(context, controllerName, actionName, dataAdapter);

                stopwatch.Stop();
                if (stopwatch.ElapsedMilliseconds > 5000)
                {
                    Logger.Debug(string.Format("{0}耗时较长, 耗时:{1}ms", context.Request.Url.ToString(), stopwatch.ElapsedMilliseconds));
                }
            }
            catch (Exception e)
            {
                string error = ResourceUtil.ReadToEndFromCache(typeof(MvcDispatcher).Assembly, "Bee.Web.Error.htm", false);

                context.Response.Write(string.Format(error, e.Message, GetFullException(e)));

                Logger.Error(e.Message, e);

                Logger.Log(LogLevel.Core, e.Message, e);
            }
        }
Exemple #2
0
 /// <summary>
 /// Before execute the action.
 /// </summary>
 protected virtual void ActionExecuting(ActionExecutingArgs actionExcutingArgs)
 {
 }