很多人用ActionlessForm来解决这个问题,可是把每个form都改成ActionlessForm的工作量确实太大。
如果你的系统中已定义了叶面基类,那么问题可就简单的多了:
protected override void OnLoadComplete(EventArgs e)
{
string originalUrl = Context.Items["OriginalUrl"] as string;
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('?');
很多人用ActionlessForm来解决这个问题,可是把每个form都改成ActionlessForm的工作量确实太大。
如果你的系统中已定义了叶面基类,那么问题可就简单的多了:
首先在重写时把原始url记录在Context.Items["OriginalUrl"]中,
然后在页面基类中重写下面方法:
protected override void OnLoadComplete(EventArgs e) { string originalUrl = Context.Items["OriginalUrl"] as string;
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); }
LoadComplete之后再把地址重写回来就够了。 |
|