Exemplo n.º 1
0
        /// <summary>重启网站</summary>
        public static void RebootSite()
        {
            var path = Asp.MapPath("~/web.config");

            using (var writer = new StreamWriter(path, true))
            {
                writer.WriteLine();
                writer.Close();
            }
        }
Exemplo n.º 2
0
        //-------------------------------------
        // Html
        //-------------------------------------

        /*
         * /// <summary>在页面头部注册移动端适配的meta语句</summary>
         * public static void RegistMobileMeta()
         * {
         *  HtmlHead head = Page.Header;
         *  HtmlMeta meta = new HtmlMeta();
         *  meta.Name = "viewport";
         *  meta.Content = "width=device-width, initial-scale=1.0";
         *  head.Controls.AddAt(0, meta);
         * }
         */

        /*
         * /// <summary>在页面头部注册CSS</summary>
         * public static void RegistCSS(string url, bool appendOrInsert=true)
         * {
         *  url = ResolveUrl(url);
         *  HtmlLink css = new HtmlLink();
         *  css.Href = url;
         *  css.Attributes.Add("rel", "stylesheet");
         *  css.Attributes.Add("type", "text/css");
         *  var header = (HttpContext.Current.Handler as Page).Header;
         *  if (appendOrInsert)
         *      header.Controls.Add(css);
         *  else
         *      header.Controls.AddAt(0, css);
         * }
         */

        /*
         * /// <summary>在页面头部注册脚本</summary>
         * public static void RegistScript(string url)
         * {
         *  HtmlGenericControl script = new HtmlGenericControl("script");
         *  script.Attributes.Add("type", "text/javascript");
         *  script.Attributes.Add("src", url);
         *  (Asp.Current.Handler as Page).Header.Controls.Add(script);
         * }
         */

        /*
         * /// <summary>创建POST表单并跳转页面</summary>
         * public static void CreateFormAndPost(Page page, string url, Dictionary<string, string> data)
         * {
         *  // 构建表单
         *  string formID = "PostForm";
         *  StringBuilder sb = new StringBuilder();
         *  sb.AppendFormat(@"<form id=""{0}"" name=""{0}"" action=""{1}"" method=""POST"">", formID, url);
         *  foreach (var item in data)
         *      sb.AppendFormat(@"<input type=""hidden"" name=""{0}"" value='{1}'>", item.Key, item.Value);
         *  sb.Append("</form>");
         *
         *  // 创建js执行Form
         *  sb.Append(@"<script type=""text/javascript"">");
         *  sb.AppendFormat("var postForm = document.{0};", formID);
         *  sb.Append("postForm.submit();");
         *  sb.Append("</script>");
         *  page.Controls.Add(new LiteralControl(sb.ToString()));
         * }
         */


        //-------------------------------------------
        // Url & Path
        //-------------------------------------------
        /// <summary>是否是本网站文件(如果以.~/开头或host相同是本站图片)</summary>
        public static bool IsSiteFile(this string url)
        {
            if (url.IsEmpty())
            {
                return(false);
            }
            if (url.StartsWith("/") || url.StartsWith("~/") || url.StartsWith("."))
            {
                return(true);
            }
            url = Asp.ResolveUrl(url);
            Uri uri = new Uri(url);

            return(uri.Host.ToLower() == Request.Host.Value.ToLower());
        }
Exemplo n.º 3
0
 /// <summary>将物理路径转化为虚拟路径</summary>
 public static string ToVirtualPath(this string physicalPath)
 {
     return(physicalPath.ToRelativePath(Asp.MapPath("/")).Replace("\\", "/"));
 }