也谈UpdatePanel与UrlRewrite一起work时出现Form Action属性的问题

首先感谢老赵写了一篇文章, http://www.cnblogs.com/JeffreyZhao/archive/2006/12/27/604373.aspx#post

其实出现这个问题,根本不是MS Ajax的失误,完全是我们没有用好URLRewrite这个东西的原因。

老赵的解决方法是重写了一个Form类,把原来的Form的Action给清空了。

能否正常工作我不知道,但是我认为“清空”,“利用默认属性”这样一类的做法是很危险的。~~~

重写Form类的,引用也有点麻烦,我觉的重写一个Page,比较方便。我在 www.365rss.cn 中的做法如下:

None.gif using  System;
None.gif
using  System.IO;
None.gif
using  System.Web;
None.gif
using  System.Web.UI;
None.gif
namespace  okpower.Utility
ExpandedBlockStart.gif
{
ExpandedSubBlockStart.gif    
/// <summary>
InBlock.gif    
/// URLRewrite 页面基类
InBlock.gif    
/// 作者:Kai.Ma http://kaima.cnblogs.com
ExpandedSubBlockEnd.gif    
/// </summary>
InBlock.gif    public class URLRewritePage : Page
ExpandedSubBlockStart.gif    
{
InBlock.gif        
public URLRewritePage()
ExpandedSubBlockStart.gif        
{
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected override void Render(HtmlTextWriter writer)
ExpandedSubBlockStart.gif        
{            
InBlock.gif            writer 
= new FormFixerHtmlTextWriter(writer.InnerWriter);
InBlock.gif            
base.Render(writer);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
internal class FormFixerHtmlTextWriter : System.Web.UI.HtmlTextWriter
ExpandedSubBlockStart.gif    
{
InBlock.gif        
private string _url;
InBlock.gif        
internal FormFixerHtmlTextWriter(TextWriter writer)
InBlock.gif            : 
base(writer)
ExpandedSubBlockStart.gif        
{
InBlock.gif            _url 
= HttpContext.Current.Request.RawUrl;
ExpandedSubBlockEnd.gif        }

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

InBlock.gif
InBlock.gif            
base.WriteAttribute(name, value, encode);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedBlockEnd.gif}
以后继承这个URLRewritePage就可以了,甚至可以进web.config设置,一劳永逸。

欢迎交流


本文转自Kai的世界,道法自然博客园博客,原文链接:http://www.cnblogs.com/kaima/archive/2006/12/27/604758.html,如需转载请自行联系原作者。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值