开发者

Invalid viewstate when using RewritePath

I have this in my global.asax

void Application_BeginRequest(object sender, EventArgs e) 
{
    string pathAndQuery = Request.Url.PathAndQuery.ToString().ToLower();
    if (pathAndQuery.Contains("prettyUrl"))
    {
        Ht开发者_高级运维tpContext.Current.RewritePath("Category.aspx?catg=uglyUrl");
    }
}

it works fine, but I sometimes get this 500 unable to validate data so i guess that is because the checksum is generated on behalf of the url. which does not match the viewstate.

So how do you solve it so that you can use RewritePath but don't get the 500 errors?

Edit forgot to mention that i have a static machinekey validationkey in the web.config

Edit2 found someone else has exactly the same problem: http://bytes.com/topic/asp-net/answers/298680-form-action-context-rewritepath#post1172026

the rewritepath causes an invalid viewstate when there is a postback


Switching from to maproutes from System.Web.Routing

Old code:

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");
    }
}

New code:

source: 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");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜