高手请帮忙.关于URL重写后 action的问题
using System;
using System.IO;
using System.Web;
using System.Web.UI;
namespace URL
{
public class OLPage : Page
{
public OLPage()
{}
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);
}}
internal class FormFixerHtml32TextWriter : System.Web.UI.Html32TextWriter
{
private string _url; // 假的URL
internal FormFixerHtml32TextWriter(TextWriter writer):base(writer)
{
_url = HttpContext.Current.Request.RawUrl;
}
public override void WriteAttribute(string name, string value, bool encode)
{
if (_url != null && string.Compare(name, "action ", true) == 0)
{
value = _url;
}
base.WriteAttribute(name, value, encode);
}
}
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)
{
if (_url != null && string.Compare(name, "action ", true) == 0)
{
value = _url;
}
base.WriteAttribute(name, value, encode);
}}}
把这个文件编译成dll,并在你的项目中引用它。
然后把项目中的所有aspx文件对应的cs文件中的继承page类的代码改写为继承OLPage。
例如
public class WebForm1:page
改写为
public class WebForm1:URL.OLPage
为何我这样做了但form 里的action 还是一点改变都没有的,
http://localhost/member/register.html
但form action= "register.aspx "
这是为什么呢,高手请帮忙
------解决方案--------------------http://www.51aspx.com/S/urlrewrite.aspx
------解决方案--------------------改是改了,估计你在action之后还有代码运行