using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Drawing; using System.Text; using System.IO; using System.Threading; namespace HH.WMS.Utils { public class ZScript { #region Alert() /**/ /// /// 简单弹出对话框功能 /// 代码调用: /// UIHelper.Alert(this.Page,"OKOK"); /// /// /// /// /// 当前的页面 /// /// /// 弹出信息的内容 /// public static void Alert(System.Web.UI.Page pageCurrent, string strMsg) { //Replace \n strMsg = strMsg.Replace("\n", "file://n/"); //Replace \r strMsg = strMsg.Replace("\r", "file://r/"); //Replace " strMsg = strMsg.Replace("\"", "\\\""); //Replace ' strMsg = strMsg.Replace("\'", "\\\'"); pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), System.Guid.NewGuid().ToString(), "" ); //以下代码是兼容.net1.1版本的,但到了2.0时代此API就过时了 //pageCurrent.RegisterStartupScript( // System.Guid.NewGuid().ToString(), // "" // ); } public static void Alert(System.Web.UI.Page pageCurrent, string strMsg, string GoBackUrl) { //Replace \n strMsg = strMsg.Replace("\n", "file://n/"); //Replace \r strMsg = strMsg.Replace("\r", "file://r/"); //Replace " strMsg = strMsg.Replace("\"", "\\\""); //Replace ' strMsg = strMsg.Replace("\'", "\\\'"); pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), System.Guid.NewGuid().ToString(), "" ); //以下代码是兼容.net1.1版本的,但到了2.0时代此API就过时了 //pageCurrent.RegisterStartupScript( // System.Guid.NewGuid().ToString(), // "" // ); } #endregion #region ScrollMessage /**/ /// /// 简单的滚动信息栏 /// 代码调用 /// UIHelper.ScrollMessage(this.Page, "滚动的内容"); /// /// /// 当前页面 /// /// /// 要滚动的信息 /// public static string ScrollMessage(string strMsg) { //Replace \n strMsg = strMsg.Replace("\n", "file://n/"); //Replace \r strMsg = strMsg.Replace("\r", "file://r/"); //Replace " strMsg = strMsg.Replace("\"", "\\\""); //Replace ' strMsg = strMsg.Replace("\'", "\\\'"); StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(strMsg); sb.Append(""); return sb.ToString(); //pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), // System.Guid.NewGuid().ToString(),sb.ToString()); } /**/ /// /// 指定滚动文字的详细方法 /// /// /// /// 当前的页面 /// /// /// 要滚动的文字 /// /// /// align:是设定活动字幕的位置,居左、居中、居右、靠上和靠下三种位置 /// left center right top bottom /// /// /// 用于设定活动字幕的背景颜色,一般是十六进制数。如#CCCCCC /// /// /// 用于设定活动字幕的滚动方向是向左、向右、向上、向下 /// left|right|up|down /// /// /// 用于设定滚动的方式,主要由三种方式:scroll slide和alternate /// /// /// /// 用于设定滚动字幕的高度 /// /// /// /// 则设定滚动字幕的宽度 /// /// /// 用于设定活动字幕的滚动距离 /// /// /// 用于设定滚动两次之间的延迟时间 /// /// /// /// 分别用于设定滚动字幕的左右边框和上下边框的宽度 /// /// /// /// 用于设定滚动的次数,当loop=-1表示一直滚动下去,直到页面更新 /// /// /// 脚本的存放位置 /// /// public static string ScrollMessage(System.Web.UI.Page pageCurrent, string strMsg, string aligh, string bgcolor, string direction, string behavior, string height, string hspace, string scrollamount, string scrolldelay, string width, string vspace, string loop, string MarqueejavascriptPath) { StreamReader sr = new StreamReader(pageCurrent.MapPath(MarqueejavascriptPath)); StringBuilder sb = new StringBuilder(); string line; try { while ((line = sr.ReadLine()) != null) { sb.AppendLine(line); } sr.Close(); } catch (Exception ex) { throw new Exception(ex.Message); } sb.Replace("$strMessage", strMsg); sb.Replace("$aligh", aligh); sb.Replace("$bgcolor", bgcolor); sb.Replace("$direction", direction); sb.Replace("$behavior", behavior); sb.Replace("$height", height); sb.Replace("$hspace", hspace); sb.Replace("$scrollamount", scrollamount); sb.Replace("$scrolldelay", scrolldelay); sb.Replace("$width", width); sb.Replace("$vspace", vspace); sb.Replace("$loop", loop); //pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), // System.Guid.NewGuid().ToString(), sb.ToString()); return sb.ToString(); } #endregion #region Redirect() /**/ /// /// Add the javascript method to redirect page on client /// Created : Wang Hui, May 18,2006 /// Modified: /// /// /// public static void Redirect(System.Web.UI.Page pageCurrent, string strPage) { pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), System.Guid.NewGuid().ToString(), "" ); //以下方法是兼容1.1的,2.0过时 //pageCurrent.RegisterStartupScript( // System.Guid.NewGuid().ToString(), // "" // ); } /**/ /// /// 主要用于跳出带有框架的页面 /// /// 当前页面如this.page /// 要跳出的页面 public static void RedirectFrame(System.Web.UI.Page pageCurrent, string strPage) { pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), System.Guid.NewGuid().ToString(), "" ); //以下方法是兼容1.1的,2.0过时 //pageCurrent.RegisterStartupScript( // System.Guid.NewGuid().ToString(), // "" // ); } #endregion #region AddConfirm /**/ /// /// Add the confirm message to button /// Created : GuangMing Chu 1,1,2007 /// Modified: GuangMing Chu 1,1,2007 /// Modified: GuangMing Chu 1,1,2007 /// 代码调用: /// UIHelper.AddConfirm(this.Button1, "真的要删了??"); /// 点确定按钮就会执行事件中的代码,点取消不会 /// /// The control, must be a button /// The popup message public static void AddConfirm(System.Web.UI.WebControls.Button button, string strMsg) { strMsg = strMsg.Replace("\n", "file://n/"); strMsg = strMsg.Replace("\r", "file://r/"); strMsg = strMsg.Replace("\"", "\\\""); strMsg = strMsg.Replace("\'", "\\\'"); button.Attributes.Add("onClick", "return confirm('" + strMsg + "')"); } /**/ /// /// Add the confirm message to button /// Created : GuangMing Chu, 1 1,2007 /// Modified: GuangMing Chu, 1 1,2007 /// Modified: /// 代码调用: /// UIHelper.AddConfirm(this.Button1, "真的要删了??"); /// 点确定按钮就会执行事件中的代码,点取消不会 /// /// /// The control, must be a button /// The popup message public static void AddConfirm(System.Web.UI.WebControls.ImageButton button, string strMsg) { strMsg = strMsg.Replace("\n", "file://n/"); strMsg = strMsg.Replace("\r", "file://r/"); strMsg = strMsg.Replace("\"", "\\\""); strMsg = strMsg.Replace("\'", "\\\'"); button.Attributes.Add("onClick", "return confirm('" + strMsg + "')"); } /**/ /// /// Add the confirm message to one column of gridview /// 代码调用: /// UIHelper myHelp = new UIHelper(); /// myHelp.AddConfirm(this.GridView1,1, "ok"); /// 请使用时注意,此方法的调用必须实例化,调用 /// /// The control, must be a GridView /// The column index. It's usually the column which has the "delete" button. /// The popup message public static void AddConfirm(System.Web.UI.WebControls.GridView grid, int intColIndex, string strMsg) { strMsg = strMsg.Replace("\n", "file://n/"); strMsg = strMsg.Replace("\r", "file://r/"); strMsg = strMsg.Replace("\"", "\\\""); strMsg = strMsg.Replace("\'", "\\\'"); for (int i = 0; i < grid.Rows.Count; i++) { grid.Rows[i].Cells[intColIndex].Attributes.Add("onclick", "return confirm('" + strMsg + "')"); } } #endregion #region AddShowDialog /**/ /// /// Add the javascript method showModalDialog to button /// 为Button按钮加入一个弹出窗体对话框 /// 代码调用 /// UIHelper.AddShowDialog(this.Button1, "www.sina.com.cn", 300, 300); /// /// /// /// /// The control, must be a button /// The page url, including query string /// Width of window /// Height of window public static void AddShowDialog(System.Web.UI.WebControls.Button button, string strUrl, int intWidth, int intHeight) { string strScript = ""; strScript += "var strFeatures = 'dialogWidth=" + intWidth.ToString() + "px;dialogHeight=" + intHeight.ToString() + "px;center=yes;help=no;status=no';"; strScript += "var strName ='';"; if (strUrl.Substring(0, 1) == "/") { strUrl = strUrl.Substring(1, strUrl.Length - 1); } strUrl = BaseUrl + "DialogFrame.aspx?URL=" + strUrl; strScript += "window.showModalDialog(\'" + strUrl + "\',window,strFeatures);return false;"; button.Attributes.Add("onClick", strScript); } #endregion #region AddShowDialog /**/ /// /// Add the javascript method showModalDialog to button /// /// The control, must be a link button /// The page url, including query string /// Width of window /// Height of window public static void AddShowDialog(System.Web.UI.WebControls.LinkButton button, string strUrl, int intWidth, int intHeight) { string strScript = ""; strScript += "var strFeatures = 'dialogWidth=" + intWidth.ToString() + "px;dialogHeight=" + intHeight.ToString() + "px;center=yes;help=no;status=no';"; strScript += "var strName ='';"; if (strUrl.Substring(0, 1) == "/") { strUrl = strUrl.Substring(1, strUrl.Length - 1); } strUrl = BaseUrl + "DialogFrame.aspx?URL=" + strUrl; strScript += "window.showModalDialog(\'" + strUrl + "\',strName,strFeatures);return false;"; button.Attributes.Add("onClick", strScript); } #endregion #region AddShowDialog /**/ /// /// Add the javascript method showModalDialog to button /// /// The control, must be a button /// The page url, including query string /// Width of window /// Height of window public static void AddShowDialog(System.Web.UI.WebControls.ImageButton button, string strUrl, int intWidth, int intHeight) { string strScript = ""; strScript += "var strFeatures = 'dialogWidth=" + intWidth.ToString() + "px;dialogHeight=" + intHeight.ToString() + "px;center=yes;help=no;status=no';"; strScript += "var strName ='';"; if (strUrl.Substring(0, 1) == "/") { strUrl = strUrl.Substring(1, strUrl.Length - 1); } strUrl = BaseUrl + "DialogFrame.aspx?URL=" + strUrl; strScript += "window.showModalDialog(\'" + strUrl + "\',window,strFeatures);return false;"; button.Attributes.Add("onClick", strScript); } #endregion #region ClearTextBox /**/ /// /// 将选定的TextBox值清空 /// /// public static void ClearTextBox(System.Web.UI.WebControls.TextBox myTextBox) { myTextBox.Attributes.Add("onclick", "this.value=''"); } #endregion #region OpenWindow /**/ /// /// Use "window.open" to popup the window /// Created : Wang Hui, Feb 24,2006 /// Modified: Wang Hui, Feb 24,2006 /// 打开窗体的对话框功能 /// 代码调用: /// /// /// UIHelper.OpenWindow(this.Page, "www.sina.com.cn", 400, 300); /// UIHelper.ShowDialog(this.Page, "lsdjf.com", 300, 200); /// /// /// /// /// The url of window, start with "/", not "http://" /// Width of popup window /// Height of popup window public static void OpenWindow(System.Web.UI.Page pageCurrent, string strUrl, int intWidth, int intHeight, int intLeft, int intTop, string WinName) { #region 老版本 //string strScript = ""; //strScript += "var strFeatures = 'width:" + intWidth.ToString() + "px;height:" + intHeight.ToString() + "px';"; //strScript += "var strName ='__WIN';"; /**/ ////strScript += "alert(strFeatures);"; ////--- Add by Wang Hui on Feb 27 //if (strUrl.Substring(0, 1) == "/") //{ // strUrl = strUrl.Substring(1, strUrl.Length - 1); //} /**/ ////--- End Add by Wang Hui on Feb 27 //strUrl = BaseUrl + strUrl; //strScript += "window.open(\"" + strUrl + "\",strName,strFeatures);"; //pageCurrent.RegisterStartupScript( // System.Guid.NewGuid().ToString(), // "" // ); //pageCurrent.RegisterStartupScript( // System.Guid.NewGuid().ToString(), // "" // ); #endregion StringBuilder sb = new StringBuilder(); sb.AppendFormat(@"myleft={0};mytop={1};", intLeft.ToString(), intTop.ToString()); sb.AppendLine(); sb.AppendFormat(@"settings='top=' + mytop + ',left=' + myleft + ',width={0},height={1},location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,fullscreen=no';", intWidth.ToString(), intHeight.ToString()); sb.AppendLine(); sb.AppendFormat(@"window.open('{0}','{1}', settings);", strUrl, WinName); pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), System.Guid.NewGuid().ToString(), "" ); } #endregion #region ShowDialog /**/ /// /// Use "window.showModalDialog" to show the dialog /// Created : Wang Hui, Feb 24,2006 /// Modified: Wang Hui, Feb 27,2006 /// 此窗体是模式窗体,和C/S结构中的模式窗体是一致的 /// /// The url of dialog, start with "/", not "http://" /// Width of dialog /// Height of dialog public static void ShowDialog(System.Web.UI.Page pageCurrent, string strUrl, int intWidth, int intHeight) { string strScript = ""; strScript += "var strFeatures = 'dialogWidth=" + intWidth.ToString() + "px;dialogHeight=" + intHeight.ToString() + "px;center=yes;help=no;status=no';"; strScript += "var strName ='';"; //--- Add by Wang Hui on Feb 27 if (strUrl.Substring(0, 1) == "/") { strUrl = strUrl.Substring(1, strUrl.Length - 1); } //--- End Add by Wang Hui on Feb 27 strUrl = BaseUrl + "DialogFrame.aspx?URL=" + strUrl; //strScript += "window.showModalDialog(\"" + strUrl + "\",strName,strFeatures);"; strScript += "window.showModalDialog(\"" + strUrl + "\",window,strFeatures); "; pageCurrent.ClientScript.RegisterStartupScript( pageCurrent.GetType(), System.Guid.NewGuid().ToString(), "" ); } #endregion #region CloseWindows /**/ /// /// 关闭窗体,没有任何提示的关闭窗体 /// /// public static void CloseWindows(System.Web.UI.Page pageCurrent) { StringBuilder sb = new StringBuilder(); sb.Append(""); pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), System.Guid.NewGuid().ToString(), sb.ToString()); } /**/ /// /// 有提示信息的关闭窗体 /// /// /// public static void CloseWindows(System.Web.UI.Page pageCurrent, string strMessage) { StringBuilder sb = new StringBuilder(); sb.Append(""); pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), System.Guid.NewGuid().ToString(), sb.ToString()); } /**/ /// /// 有等待时间的关闭窗体 /// /// /// 等待时间,以毫秒为记量单位 public static void CloseWindows(System.Web.UI.Page pageCurrent, int WaitTime) { StringBuilder sb = new StringBuilder(); sb.Append(""); pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), System.Guid.NewGuid().ToString(), sb.ToString()); } #endregion #region ShowStatusBar public static void ShowStatus(System.Web.UI.Page pageCurrent, string StatusString) { StringBuilder sb = new StringBuilder(); sb.Append(""); pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), System.Guid.NewGuid().ToString(), sb.ToString()); } #endregion #region PlayMediaFile /**/ /// /// 调用Media播放mp3或电影文件 /// /// /// 当前的页面对象 /// /// /// 播放文件的位置 /// /// /// Mediajavascript的脚本位置 /// /// /// 是否可以使用右键 /// 指定是否使右键菜单有效 /// 指定右键是否好用,默认为0不好用 /// 指定为1时就是好用 /// /// /// 播放器的大小显示 /// None,mini,或full,指定Windows媒体播放器控制如何显示 /// public static string PlayMediaFile(System.Web.UI.Page pageCurrent, string PlayFilePath, string MediajavascriptPath, string enableContextMenu, string uiMode) { StreamReader sr = new StreamReader(pageCurrent.MapPath(MediajavascriptPath)); StringBuilder sb = new StringBuilder(); string line; try { while ((line = sr.ReadLine()) != null) { sb.AppendLine(line); } sr.Close(); } catch (Exception ex) { throw new Exception(ex.Message); } sb.Replace("$URL", pageCurrent.MapPath(PlayFilePath)); sb.Replace("$enableContextMenu", enableContextMenu); sb.Replace("$uiMode", uiMode); //pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), // System.Guid.NewGuid().ToString(), sb.ToString()); return sb.ToString(); } #endregion #region ShowProgBar /**/ /// /// 主要实现进度条的功能,这段代码的调用就要实现进度的调度 /// 实现主要过程 /// default.aspx.cs是调用页面 /// 放入page_load事件中 /// UIHelper myUI = new UIHelper(); /// Response.Write(myUI.ShowProgBar(this.Page,"../JS/progressbar.htm")); /// Thread thread = new Thread(new ThreadStart(ThreadProc)); /// thread.Start(); /// LoadData();//load数据 /// thread.Join(); /// Response.Write("OK"); /// /// 其中ThreadProc方法为 /// public void ThreadProc() /// { /// string strScript = ""; /// for (int i = 0; i <= 100; i++) /// { /// System.Threading.Thread.Sleep(10); /// Response.Write(string.Format(strScript, i)); /// Response.Flush(); /// } /// } /// 其中LoadData() /// public void LoadData() /// { /// for (int m = 0; m < 900; m++) /// { /// for (int i = 0; i < 900; i++) /// { /// /// } /// } /// } /// /// /// /// /// public static string ShowProgBar(System.Web.UI.Page pageCurrent, string ShowProgbarScript) { StreamReader sr = new StreamReader(pageCurrent.MapPath(ShowProgbarScript), System.Text.Encoding.Default); StringBuilder sb = new StringBuilder(); string line; try { while ((line = sr.ReadLine()) != null) { sb.AppendLine(line); } sr.Close(); } catch (Exception ex) { throw new Exception(ex.Message); } //pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), // System.Guid.NewGuid().ToString(), sb.ToString()); return sb.ToString(); } #endregion #region fixedHeader public static string fixedHeader() { StringBuilder s = new StringBuilder(); s.Append(@""); s.Append(@""); s.Append(@""); s.Append(@""); s.Append(@""); s.Append(@""); for (int m = 0; m < 100; m++) { s.Append(@""); s.Append(@""); s.Append(@""); s.Append(@""); s.Append(@""); } s.Append(@"
Header AHeader BHeader C
A").Append(m).Append("B").Append(m).Append("C").Append(m).Append("
"); return s.ToString(); } #endregion #region refreshPage public static void refreshPage(System.Web.UI.Page pageCurrent) { StringBuilder sb = new StringBuilder(); sb.Append(""); pageCurrent.ClientScript.RegisterStartupScript(pageCurrent.GetType(), System.Guid.NewGuid().ToString(), sb.ToString()); } #endregion #region Page_revealTrans //进入页面 //推出页面 //这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使用哪种特效,取值为1-23: // 0 矩形缩小 // 1 矩形扩大 // 2 圆形缩小 // 3 圆形扩大 // 4 下到上刷新 // 5 上到下刷新 // 6 左到右刷新 // 7 右到左刷新 // 8 竖百叶窗 // 9 横百叶窗 // 10 错位横百叶窗 // 11 错位竖百叶窗 // 12 点扩散 // 13 左右到中间刷新 // 14 中间到左右刷新 // 15 中间到上下 // 16 上下到中间 // 17 右下到左上 // 18 右上到左下 // 19 左上到右下 // 20 左下到右上 // 21 横条 // 22 竖条 // 23 以上22种随机选择一种 public static string Page_revealTrans(System.Web.UI.Page currentPage, string duration, string transition) { StringBuilder sb = new StringBuilder(); sb.Append(""); //currentPage.ClientScript.RegisterStartupScript(currentPage.GetType(), // System.Guid.NewGuid().ToString(), sb.ToString()); return sb.ToString(); } #endregion /// /// 显示一段自定义的输出代码 /// /// 页面指针,一般为This public static void RegisterStartupScript(System.Web.UI.Page page, string script) { var sb = new StringBuilder(); sb.Append(""); page.ClientScript.RegisterStartupScript(page.GetType(), page.GetType().Name, sb.ToString()); } public static void RegisterClientScriptBlock(System.Web.UI.Page page, string script) { var sb = new StringBuilder(); sb.Append(""); page.ClientScript.RegisterClientScriptBlock(page.GetType(), page.GetType().Name, sb.ToString()); } /**/ /// /// 调用客户端JavaScript函数 /// /// 页面指针,一般为This /// 函数名,带参数,如:FunA(1); public static void CallClientScript(System.Web.UI.Page page, string scriptName) { String csname = "PopupScript"; Type cstype = page.GetType(); System.Web.UI.ClientScriptManager cs = page.ClientScript; if (!cs.IsStartupScriptRegistered(cstype, csname)) { String cstext = scriptName; cs.RegisterStartupScript(cstype, csname, cstext, true); } } /**/ /// /// 弹出对话框(弹出对话框后css会失效) /// /// 提示信息 public static void ShowMessage(string message) { StringBuilder sb = new StringBuilder(); sb.Append(""); System.Web.HttpContext.Current.Response.Write(sb.ToString()); } /**/ /// /// 弹出对话框(不影响css样式) /// /// 页面指针,一般为this /// 脚本键,唯一 /// 提示信息 public static void ShowMessage(System.Web.UI.Page page, string scriptKey, string message) { System.Web.UI.ClientScriptManager csm = page.ClientScript; if (!csm.IsClientScriptBlockRegistered(scriptKey)) { string strScript = "alert('" + message + "');"; csm.RegisterClientScriptBlock(page.GetType(), scriptKey, strScript, true); } } /**/ /// /// 为控件添加确认提示对话框 /// /// 需要添加提示的对话框 /// 提示信息 public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string message) { Control.Attributes.Add("onclick", "return confirm('" + message + "');"); } /**/ /**/ /**/ /// /// 显示一个弹出窗口,并转向目标页(导航) /// public static void ShowAndRedirect(string message, string url) { StringBuilder sb = new StringBuilder(); sb.Append(""); System.Web.HttpContext.Current.Response.Write(sb.ToString()); } /**/ /// /// 显示一个弹出窗口,重新加载当前页 /// public static void ShowAndReLoad(string message) { StringBuilder sb = new StringBuilder(); sb.Append(""); System.Web.HttpContext.Current.Response.Write(sb.ToString()); } /**/ /// /// 显示一个弹出窗口,刷新当前页(危险的,有可能陷入死循环) /// public static void ShowAndRefresh(string message) { StringBuilder sb = new StringBuilder(); sb.Append(""); System.Web.HttpContext.Current.Response.Write(sb.ToString()); } /**/ /// /// 显示一个弹出窗口,并关闭当前页 /// /// public static void ShowAndClose(string message) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("\n"); System.Web.HttpContext.Current.Response.Write(sb.ToString()); } /**/ /// /// 显示一个弹出窗口,并转向上一页 /// /// public static void ShowPre(string message) { StringBuilder sb = new StringBuilder(); sb.Append(""); System.Web.HttpContext.Current.Response.Write(sb.ToString()); } /**/ /// /// 页面重载 /// public static void ReLoad() { StringBuilder sb = new StringBuilder(); sb.Append(""); System.Web.HttpContext.Current.Response.Write(sb.ToString()); } /**/ /// /// 重定向 /// public static void Redirect(string url) { //string path = "http://" + System.Web.HttpContext.Current.Request.Url.Host + ":" + System.Web.HttpContext.Current.Request.Url.Port + url; string path = "http://" + System.Web.HttpContext.Current.Request.Url.Host + url; StringBuilder sb = new StringBuilder(); sb.Append(""); System.Web.HttpContext.Current.Response.Write(sb.ToString()); } #region Static Property Get BaseUrl(静态属性获取URL地址) /**/ /// /// 这个静态属性的调用必须用以下代码方法调用 /// 代码调用: /// Response.Write(UIHelper.BaseUrl); /// public static string BaseUrl { get { //strBaseUrl用于存储URL地址 string strBaseUrl = ""; //获取当前HttpContext下的地址 strBaseUrl += "http://" + HttpContext.Current.Request.Url.Host; //如果端口不是80的话,那么加入特殊端口 if (HttpContext.Current.Request.Url.Port.ToString() != "80") { strBaseUrl += ":" + HttpContext.Current.Request.Url.Port; } strBaseUrl += HttpContext.Current.Request.ApplicationPath; return strBaseUrl + "/"; } } #endregion } }