Пример #1
0
        public string Action <TController>(string action) where TController : BaseController
        {
            var url = UrlUtil.Action <TController>(action);
            HttpWebRequestHelper helper = new HttpWebRequestHelper();

            return(helper.GetContent(url));
        }
Пример #2
0
        public string Action <TController>(string action, object datas) where TController : BaseController
        {
            var dic = AnonymousObjectToHtmlAttributes(datas);
            var url = UrlUtil.Action <TController>(action);

            if (dic.Count > 0)
            {
                url = url + "?";
                foreach (var kvp in dic)
                {
                    url += kvp.Key + "=" + System.Web.HttpUtility.UrlEncode(kvp.Value.ToString()) + "&";
                }
                url = url.TrimEnd('&');
            }
            HttpWebRequestHelper helper = new HttpWebRequestHelper();

            return(helper.GetContent(url));
        }
Пример #3
0
        /// <summary>
        /// 设置系统的默认页面,只能在Application_BeginRequest中调用此方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="application"></param>
        /// <param name="actionName"></param>
        public static void SetDefaultRoute <T>(this HttpApplication application, String actionName)
            where T : BaseController
        {
            var request = application.Request;
            var url     = UrlUtil.Action <T>(actionName);

            if (request.Url.AbsolutePath.EndsWith("/"))
            {
                HttpWebRequestHelper helper = new HttpWebRequestHelper();
                foreach (var key in HttpContext.Current.Request.Cookies.AllKeys)
                {
                    HttpCookie ck     = HttpContext.Current.Request.Cookies[key];
                    var        cookie = new System.Net.Cookie();
                    cookie.Name     = ck.Name;
                    cookie.Domain   = HttpContext.Current.Request.Url.Host;
                    cookie.Expires  = ck.Expires;
                    cookie.HttpOnly = ck.HttpOnly;
                    cookie.Path     = ck.Path;
                    cookie.Value    = ck.Value;
                    helper.CookieContainer.Add(cookie);
                }
                string content = null;
                try
                {
                    content = helper.GetContent(url);
                }
                catch (Exception)
                {
                    application.Response.Redirect(url);
                    return;
                }
                application.Response.Write(content);
                application.Response.StatusCode  = 200;
                application.Response.ContentType = "text/html";
                application.Response.Flush();
                application.Response.End();
            }
        }