参考:http://www.cnblogs.com/jzywh/archive/2007/12/20/urlrewriteaction.html
在页面的基类中重写如下:
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
Context.Items["OriginalUrl"] = HttpContext.Current.Request.RawUrl;
base.OnInit(e);
}
protected override void OnLoadComplete(EventArgs e)
{
string originalUrl = Convert.ToString( Context.Items["OriginalUrl"]);
if (!string.IsNullOrEmpty(originalUrl)) //So this page have been urlrewriten, after the page onloaded, rewrite the url of this page to original url
{
string query = string.Empty;
int pos = originalUrl.IndexOf('?');
if (pos >= 0)// check if has query parameter
{
query = originalUrl.Substring(pos + 1);
originalUrl = originalUrl.Substring(0, pos);
}
Context.RewritePath(originalUrl, string.Empty, query);
}
base.OnLoadComplete(e);
}