也谈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 中的做法如下:

using  System;
using  System.IO;
using  System.Web;
using  System.Web.UI;
namespace  okpower.Utility
{
    
/// <summary>
    
/// URLRewrite 页面基类
    
/// 作者:Kai.Ma http://kaima.cnblogs.com
    
/// </summary>

    public class URLRewritePage : Page
    
{
        
public URLRewritePage()
        
{
        }


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

    }


    
internal class FormFixerHtmlTextWriter : System.Web.UI.HtmlTextWriter
    
{
        
private string _url;
        
internal FormFixerHtmlTextWriter(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);
        }

    }


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

欢迎交流


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

目录
相关文章
|
10月前
|
完美解决 Could not resolve placeholder ‘jeecg.file-view-domain‘ in value “${jeecg.file-view-domain}
完美解决 Could not resolve placeholder ‘jeecg.file-view-domain‘ in value “${jeecg.file-view-domain}
164 0
|
10月前
使用Form报错提示If ngModel is used within a form tag, either the name attribute must be set or the form
使用Form报错提示If ngModel is used within a form tag, either the name attribute must be set or the form
Fullpage.js version 3 has changed its license to GPLv3 and it requires a `licenseKey` option ...
Fullpage.js version 3 has changed its license to GPLv3 and it requires a `licenseKey` option ...
184 0
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
Cannot find source code based button in SE24
When you are logging on to customer system for incident handling, you want to switch to source code to perform some keyword search. However, you could not find button “Source code based builder” in toolbar, with following warning message: ———————————————— 版权声明:本文为CSDN博主「汪子熙」的原创文章,遵循CC 4.0 BY-SA版权协
Cannot find source code based button in SE24
艾伟:Tip:自定义UpdatePanelTrigger
  大家在使用UpdatePanel的时候有没有遇到过这种情况呢?   页面上放置着3到4的UpdatePanel,它们互相独立,并且UpdateMode都是Condition,这意味着没有哪个UpdatePanel每次都会更新。
981 0
jquery(live)中File input的change方法只起一次作用的解决办法
jquery中File input的change方法只起一次作用的解决办法,需要的朋友可以参考下。 错误写法 复制代码代码如下: $(“#uploadImg”).
1319 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等