经过一段努力,本站终于过RewritePath重写Url的方法实现了伪静态,但是前些天在使用本站的搜索功能时,发现只要点击搜索按钮,页面就定向到本页面的原始地址了。在网上搜索解决方案如下:1,新建BasePage.cs类文件,使用该类继承自System.Web.UI.Page。
2,重写BasePage类的Render方法,全部代码如下:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.IO;
namespace PersonalWeb.PublicCs
{
public class BasePage : System.Web.UI.Page
{
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;
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);
}
}
}
3,所有实现了伪静态的页面都改为继承BasePage类
如何通过RewritePath重写Url请参考本站:
如何通过RewritePath方法重写Url地址实现伪静态