2010-10-04 37 views
1

当我有这个在我的Global.asax无效的视图状态使用RewritePath

void Application_BeginRequest(object sender, EventArgs e) 
{ 
    string pathAndQuery = Request.Url.PathAndQuery.ToString().ToLower(); 
    if (pathAndQuery.Contains("prettyUrl")) 
    { 
     HttpContext.Current.RewritePath("Category.aspx?catg=uglyUrl"); 
    } 
} 

它工作正常,但我有时会得到这个500无法验证数据 所以我想这是因为生成的校验代表网址。这与视图状态不匹配。

那么你如何解决这个问题,以便你可以使用RewritePath但是没有得到500错误?

编辑忘了提,我有一个静态的machineKey的validationKey在web.config

EDIT2发现别人有完全一样的问题:http://bytes.com/topic/asp-net/answers/298680-form-action-context-rewritepath#post1172026

的rewritepath导致一个无效的视图状态时,有回传

+0

你有你想问一个问题吗? – Sorpigal 2010-10-04 12:13:00

回答

1

System.Web.Routing转换为maproutes

旧代码:

void Application_BeginRequest(object sender, EventArgs e) 
{ 
    string pathAndQuery = Request.Url.PathAndQuery.ToString().ToLower(); 

    if (pathAndQuery.Contains("thisisawesome")) 
    { 
     HttpContext.Current.RewritePath("Products.aspx?catg=14&cat=161"); 
    } 
} 

新代码:

来源: http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx

void Application_Start(object sender, EventArgs e) 
{ 
    RegisterRoutes(RouteTable.Routes); 
} 

void RegisterRoutes(RouteCollection routes) 
{ 
    routes.MapPageRoute("test", 
         "thisisawesome", 
         "~/Products.aspx?catg=14&cat=161"); 
} 
相关问题