url重写以后保持postback地址

让所有页面集成一下类即可实现url重写以后保持postback地址

  
  
using System;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Configuration;

namespace BLL
{
/// <summary>
/// PageBase 的摘要说明。
/// </summary>
public class PageBase : Page
{
private static object obj = new object ();
/// / <summary>
/// 重写默认的HtmlTextWriter方法,修改form标记中的value属性,使其值为重写的URL而不是真实URL。www.SvnHost.cn
/// </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);
}
}

public class FormFixerHtml32TextWriter : System.Web.UI.Html32TextWriter
{
public FormFixerHtml32TextWriter(TextWriter writer)
:
base (writer)
{
}

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


public class FormFixerHtmlTextWriter : System.Web.UI.HtmlTextWriter
{
public FormFixerHtmlTextWriter(TextWriter writer)
:
base (writer)
{
}

public override void WriteAttribute( string name, string value, bool encode)
{
if ( string .Compare(name, " action " , true ) == 0 )
{
value
= HttpContext.Current.Request.RawUrl;
}

base .WriteAttribute(name, value, encode);
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值