Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > PostBackUrl breaks url rewrite (Bug or unwanted feature).

Thread Tools

PostBackUrl breaks url rewrite (Bug or unwanted feature).

Posts: n/a
Can not figure out why but if I have button with PostBackUrl specified it
breaks UrlRewrite. All buttons stop working. Form submits but corresponded
event procedure never called. And it only happens in rewritten urls.
Do not understand why it a happens, hope some one from Microsoft would took
a look at it. I spent about a day trying to pinpoint a problem. Finaly did.

Here are simple steps to reproduce the problem

1. Create project UrlRewrite.
2. In Global.asax write following code (to rewrite every .aspx request to
default.aspx, we do not want to rewrite request for WebResource.axd)
void Application_BeginRequest(Object sender, EventArgs e)
System.Web.HttpContext ctx = System.Web.HttpContext.Current;
string sPath = ctx.Request.Path.ToLower();
//check that we have request for .aspx page
int iIndex = sPath.IndexOf(".aspx");
if (iIndex == -1)

ctx.Items["OriginalPath"] = sPath;
ctx.RewritePath("~/default.aspx", null, null);


3. Make default.aspx
<%@ Page Language="C#"%>
<script runat="server">
protected override void OnInit(EventArgs e)
//Fix HtmlForm action for proper rewrite.
string sPath = (string)Context.Items["OriginalPath"];
Context.RewritePath(sPath, "", "");
protected void Button1_Click(object sender, EventArgs e)
Button1.Text = "Success";
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Try Me" />
<asp:Button ID="goBtn" runat="server" Text="Button"

by looking at this code you would say that when you hit Button1, Text =
"Try Me" will be replaced by "Success"

Start your project.
Url http://localhost/UrlRewrite/default.aspx works as expected
Url http://localhost/UrlRewrite/Test/default.aspx does not work, form
submits but button1_Click never called.

Remove PostBackUrl="/test.aspx" from goBtn and it starts working.


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
UpdatePanel ( url rewrite) 2nd post back url changes Martin ASP .Net 0 04-28-2010 11:47 AM
Enable a button via javascript with PostBackUrl set -> the postbackurl doesn't work Fabio Mastria ASP .Net 2 03-04-2008 09:23 AM
Unwanted line-breaks in e-mail messages INTPN Computer Information 2 06-23-2007 07:10 PM
CSS URL rewrite Cisco 1 01-18-2006 04:38 PM
Rewrite asp url as aspx url? =?Utf-8?B?VA==?= ASP .Net 5 07-24-2005 05:58 PM