zoukankan      html  css  js  c++  java
  • 也谈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设置,一劳永逸。
    欢迎交流
  • 相关阅读:
    [codeforces] 97B Superset || 平面分治
    [hdu] 5696 区间的价值 || 序列分治
    [zoj] 1937 [poj] 2248 Addition Chains || ID-DFS
    [poj] 2286 The Rotation Game || ID-DFS
    [codeforces] 25E Test || hash
    luogu P1196 银河英雄传说
    luogu P1357 花园
    luogu P1156 垃圾陷阱
    luogu P1127 词链
    luogu P1131 时态同步
  • 原文地址:https://www.cnblogs.com/kaima/p/604758.html
Copyright © 2011-2022 走看看