Exemplo n.º 1
0
        /// <summary>
        /// 使用指定路由和路由处理程序初始化 <see cref="AshxRouteData"/> 类的新实例。
        /// </summary>
        /// <param name="routeContext">封装与所定义路由匹配的 HTTP 请求的相关信息。</param>
        /// <param name="jsonOptions">json配置对象</param>
        public AshxRouteData(RouteContext routeContext, System.Text.Json.JsonSerializerOptions jsonOptions)
        {
            this.JsonOptions = jsonOptions;

            this.RouteContext = routeContext;
            this.GetRouteData = routeContext.RouteData;
            this.HttpContext  = routeContext.HttpContext;

            this.HttpContext.Request.RouteValues = this.GetRouteData.Values;
            //this.Service = this.HttpContext.RequestServices;
            this.IsAshx = true;
            try
            {
                this.Area       = GetRequiredString("area");
                this.Controller = GetRequiredString("controller");
                this.Action     = GetRequiredString("action");
            }
            catch (Exception)
            {
                throw HttpContext.AddHttpException(404, string.Format(System.Globalization.CultureInfo.CurrentCulture, "找不到该路由的控制器,,URL: {0}", new object[] { this.HttpContext.Request.Path }));
            }
        }