/// <summary> /// Use a custom HtmlTextWriter to render the page if the url is rewritten, to correct the form action. /// </summary> /// <param name="writer"></param> protected override void Render(System.Web.UI.HtmlTextWriter writer) { if (Context.Items["VirtualUrl"] != null) { writer = new FormFixerHtmlTextWriter(writer.InnerWriter, "", Context.Items["VirtualUrl"].ToString()); } base.Render(writer); }
/// <summary> /// Use a custom HtmlTextWriter to render the page if the url is rewritten, to correct the form action. /// </summary> /// <param name="writer"></param> protected override void Render(System.Web.UI.HtmlTextWriter writer) { InsertStylesheets(); InsertJavaScripts(); InsertMetaTags(); if (Context.Items["VirtualUrl"] != null) { writer = new FormFixerHtmlTextWriter(writer.InnerWriter, "", Context.Items["VirtualUrl"].ToString()); } base.Render(writer); }
/// <summary> /// 重写默认的HtmlTextWriter方法,修改form标记中的value属性,使其值为重写的URL而不是真实URL。 /// </summary> /// <param name="writer"></param> protected override void Render(HtmlTextWriter writer) { if (writer is System.Web.UI.Html32TextWriter) { writer = new FormFixerHtml32TextWriter(writer.InnerWriter); } else { writer = new FormFixerHtmlTextWriter(writer.InnerWriter); } base.Render(writer); }
/// <summary> /// We override Render to swap out the default HtmlTextWriter for our own. Our own Writer's sole purpose is to /// change the the action attribute on the form tag to the vanity Url. This way all postbacks occur on the vanity url /// </summary> /// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter"></see> that receives the page content.</param> protected override void Render(HtmlTextWriter writer) { HtmlMeta generatorMeta = new HtmlMeta(); generatorMeta.Name = "GENERATOR"; generatorMeta.Content = FrameworkContext.ProductName; this.Header.Controls.Add(generatorMeta); HtmlMeta versionMeta = new HtmlMeta(); versionMeta.Name = "VERSION"; versionMeta.Content = FrameworkContext.ProductVersionDesc; this.Header.Controls.Add(versionMeta); HtmlMeta licenseMeta = new HtmlMeta(); licenseMeta.Name = "LICENSE"; CommerceLicenseInfo[] licenseInfo = CommerceLicensing.Current; if (licenseInfo == null || licenseInfo.Length == 0) { licenseMeta.Content = "unlicensed version"; } else { licenseMeta.Content = String.Format("{0} ({1})", licenseInfo[0].Edition, licenseInfo[0].Company); } this.Header.Controls.Add(licenseMeta); if (CMSContext.Current.IsUrlReWritten) { if (writer is System.Web.UI.Html32TextWriter) { writer = new FormFixerHtml32TextWriter(writer.InnerWriter); } else { writer = new FormFixerHtmlTextWriter(writer.InnerWriter); } } base.Render(writer); /* * StringWriter sw = new StringWriter(); * HtmlTextWriter hw = new HtmlTextWriter(sw); * base.Render(hw); * string html = sw.ToString(); * * // Hose the writers we don't need anymore. * hw.Close(); * sw.Close(); * * int start = html.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\""); * // If we find it, then move it. * if (start > -1) * { * int end = html.IndexOf("/>", start) + 2; * * // Strip out the viewstate. * string viewstate = html.Substring(start, end - start); * html = html.Remove(start, end - start); * * // Find the end of the form and insert it there, since we can't put it any lower in the response stream. * int formend = html.IndexOf("</form>"); * html = html.Insert(formend, viewstate); * } * * // Send the results back into the writer provided. * writer.Write(html); * */ }