Exemplo n.º 1
0
 public MvcHandler(HttpRequestContext request)
 {
     this.request = request;
 }
Exemplo n.º 2
0
 public abstract RouteData GetRouteData(HttpRequestContext requestContext);
Exemplo n.º 3
0
        public override RouteData GetRouteData(HttpRequestContext requestContext)
        {
            string requestUrl = requestContext.Context.Request.AppRelativeCurrentExecutionFilePath.Substring(2);

            try
            {
                string file = requestContext.Context.Server.MapPath("../" + requestUrl);
                if (File.Exists(file))
                {
                    return(null);
                }
            }
            catch
            { }

            int num = requestUrl.IndexOf('?');

            if (num > 0)
            {
                requestUrl = requestUrl.Substring(0, num);
            }
            requestUrl = requestUrl.ToLower();

            RouteData routeData = new RouteData(this, this.RouteHandler);

            string url = this.Url;

            if (Contoller.Length > 0 && Action.Length > 0)
            {
                url = Contoller + "/" + Action;
            }

            if (preUrl.Length > 0)
            {
                url = PreUrl + "/" + url;
            }
            url = url.ToLower();

            requestContext.Params = new Dictionary <string, object>();

            if (this.Param.Length == 0)
            {
                if (requestContext.Context.Request.HttpMethod.ToLower().Equals(HttpVerb.Get))
                {
                    //遍历QueryString
                    foreach (string key in requestContext.Context.Request.QueryString.AllKeys)
                    {
                        requestContext.Params.Add(key, requestContext.Context.Request.QueryString[key]);
                    }
                }
                else
                {
                    //遍历Forms
                    foreach (string key in requestContext.Context.Request.Form.AllKeys)
                    {
                        requestContext.Params.Add(key, requestContext.Context.Request.Form[key]);
                    }
                }
            }
            //处理带参数链接
            if (requestUrl.StartsWith(url))
            {
                string param = requestUrl.Replace(url + "/", "");
                if (param.Length > 0 && this.Param.Length > 0)
                {
                    string[] arrays = param.Split('/');
                    if (arrays.Length > this.Param.Length)
                    {
                        //参数个数不正确
                        return(null);
                    }
                    else
                    {
                        for (int i = 0; i < arrays.Length; i++)
                        {
                            requestContext.Params.Add(this.Param[i], arrays[i]);
                        }
                        requestUrl = url;
                    }
                }
            }
            else
            {
                return(null);
            }

            if (requestUrl.Equals(url))
            {
                requestContext.Controller = this.Contoller;

                requestContext.Action = this.Action;
            }
            return(routeData);
        }
Exemplo n.º 4
0
 public virtual IHttpHandler GetHttpHandler(HttpRequestContext requestContext)
 {
     return(new MvcHandler(requestContext));
 }
 public IHttpHandler GetHttpHandler(HttpRequestContext requestContext)
 {
     return(BuildManager.CreateInstanceFromVirtualPath(filePath, typeof(Page)) as Page);
 }