Tuesday, January 26, 2010

FormFixerHtml32TextWriter.cs

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.IO;
using System.Web.UI.MobileControls.Adapters;
using System.Web.Mobile;

#region FormFixerHtml32TextWriter
public class FormFixerHtml32TextWriter : System.Web.UI.HtmlTextWriter
{
private string _url; // 假的URL

public FormFixerHtml32TextWriter(TextWriter writer)
: base(writer)
{
_url = HttpContext.Current.Request.RawUrl;
}

public override void WriteAttribute(string name, string value, bool encode)
{
// 如果当前输出的属性为form标记的action属性,则将其值替换为重写后的虚假URL
if (_url != null && string.Compare(name, "action", true) == 0)
{
value = _url;
}
base.WriteAttribute(name, value, encode);
}
}
#endregion

#region FormFixerHtmlTextWriter
public class FormFixerHtmlTextWriter : HtmlMobileTextWriter

{
private string _url;
public FormFixerHtmlTextWriter(TextWriter writer,MobileCapabilities device)
: base(writer,device)
{
_url = HttpContext.Current.Request.RawUrl;

}




public override void WriteAttribute(string name, string value, bool encode)
{

if ( string.Compare(name, "action", true) == 0)
{
value = _url;
}

base.WriteAttribute(name, value, encode);
}
}
#endregion

No comments:

Post a Comment