Exemplo n.º 1
0
        public static string Action2 <T>(string method)
            where T : BaseController
        {
            var Request        = HttpContext.Current.Request;
            var baseURL        = Request.Url.Scheme + "://" + Request.Url.Authority;
            var userDefineName = UrlRouteCenter.GetUserDefineName <T>();
            var url            = baseURL + "/" + userDefineName + "/" + method + GlobalData.REQUST_SUFFIX;

            return(url);
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            //http://localhost:8081/area/Admin/Login.htm?ReturnUrl=http://localhost:8081/trtr/a.htm

            string url            = context.Request.Path.Substring(1);//        area/Admin/Login.htm
            string host           = context.Request.Url.Host;
            string actionName     = null;
            string userDefineName = null;
            int    suffixIndex    = url.LastIndexOf(GlobalData.REQUST_SUFFIX, StringComparison.OrdinalIgnoreCase);

            string tempurl = url.Substring(0, suffixIndex);           // area/Admin/Login
            var    actionNameSplitIndex = tempurl.LastIndexOf('/');   // Login前的那个分隔符的位置

            actionName = tempurl.Substring(actionNameSplitIndex + 1); // Login

            int    index   = actionNameSplitIndex;
            string urlLeft = tempurl.Substring(0, index);// area/Admin

            if (urlLeft.Contains("/") == false)
            {
                userDefineName = urlLeft;//没有域的形式,如 http://localhost:8081/Home/Index.htm
            }
            else
            {
                int index2   = urlLeft.LastIndexOf('/');      //  Admin前的分隔符位置
                var cname    = urlLeft.Substring(index2 + 1); // Admin
                var areaName = urlLeft.Substring(0, index2);  // area
                if (areaName.Contains("/"))
                {
                    string error = "The request path in RequestHandler system doesn't suppurt,context.Request.Path=" + url;
                    LogUtil.Error(error);
                    throw new Exception(error);
                }
                else
                {
                    userDefineName = urlLeft;
                }
            }
            if (string.IsNullOrEmpty(actionName) == false)
            {
                string classFullName = UrlRouteCenter.GetClassFullNameByUserDefineName(userDefineName);
                MiddleProcessUtil.Process(classFullName, actionName, context);
            }
            else
            {
                string error = "The request path in RequestHandler doesn't exist,context.Request.Path=" + url;
                LogUtil.Error(error);
                throw new Exception(error);
            }
        }
Exemplo n.º 3
0
        // http://localhost/MOON_SERVICE/ClassFullName/Method?A=3&B=4
        // http://localhost/{areas}/ClassFullName/Method/{id}
        void app_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication app          = (HttpApplication)sender;
            var             absolutePath = app.Context.Request.Url.AbsolutePath;

            if (absolutePath.StartsWith(GlobalData.MOON_SERVICE, StringComparison.OrdinalIgnoreCase))
            {
                string[] array = absolutePath.Split('/');
                if (array.Length == 4)
                {
                    string userDefineName = array[2];
                    string classFullName  = UrlRouteCenter.GetClassFullNameByUserDefineName(userDefineName);
                    string methodName     = array[3];
                    string query          = app.Context.Request.Url.Query;
                    app.Context.Items[GlobalData.CLASS_FULL_NAME] = classFullName;
                    app.Context.Items[GlobalData.METHOD_NAME]     = methodName;
                    app.Context.RewritePath(URL_PATTERN, false);
                }
            }
        }
Exemplo n.º 4
0
        public override void Response(HttpContext context, string controllerFullName, string methodName, object model, Dictionary <string, object> viewData)
        {
            string tType          = TempateEngineType.ToString();
            string virtualPath    = null;
            string controllerName = UrlRouteCenter.GetUserDefineName(controllerFullName);
            var    basString      = "~/Views/" + controllerName + "/" + methodName;

            if (string.IsNullOrEmpty(TemplateVirtualPath))
            {
                if (IsMoblieRquest(context))
                {
                    virtualPath = basString + ".Mobile." + tType;
                    var str = context.Server.MapPath(virtualPath);
                    if (File.Exists(str) == false)
                    {
                        virtualPath = basString + "." + tType;
                    }
                }
                else
                {
                    virtualPath = basString + ".PC." + tType;
                    var str = context.Server.MapPath(virtualPath);
                    if (File.Exists(str) == false)
                    {
                        virtualPath = basString + "." + tType;
                    }
                }
            }
            else
            {
                virtualPath = this.TemplateVirtualPath;
            }
            string result = null;

            result = RenderUtil.RenderAspx(context, virtualPath, model, viewData);
            SetResponseEncoding(context);
            context.Response.Write(result);
            context.Response.Flush();
            // context.Response.End();//2015年9月13日15:02:52
        }