其实出现这个问题,根本不是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设置,一劳永逸。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);
}
}
}
欢迎交流