views:

899

answers:

4

Hi, on our site we do url rewriting to generate massive amounts of database generated pages. on every page, there is a Login control for users. like this:

Internal aspx page: /DB.aspx?id=123 User visible url: /ABC/123.aspx, /ABC/456.aspx ... (url rewritten)

unfortunately, the tag on each page has an action attribute of "DB.aspx?id=123". when the user clicks the button the browser is posting to /ABC/DB.aspx?id=123 which of course does not exist.

solutions i tried: 1. change the action attribute by subclassing HtmlForm. this destroys the all other forms on the site. 2. remove the action attribute (so that the browser is always posting to the same url). this works on the rewritten pages but on "/" (the default.aspx in the root dir) i get a message that the verb post is not allowed on "/" (iis 6 and i have no control over mappings)

anybody?

A: 

Semantics maybe, but does the action attribute = "DB.aspx?id=123" or "/DB.aspx?id=123"? Assuming your URL rewriting allows pass-through to physical pages, this might be your issue.

jro
yes, the action attribute is realtive. anyway i dont want the user to see the DB.aspx. all access must go through the rewriting engine because of seo optimizations.
+1  A: 

Check this really nice blog post from scott gu, http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx.

"Specifically, you can take advantage of the new ASP.NET 2.0 Control Adapter extensibility architecture to customize the rendering of the control, and override its "action" attribute value with a value you provide. This doesn't require you to change any code in your .aspx pages"

Check the section: "Handling ASP.NET PostBacks with URL Rewriting", I have used the adapter he posted successfully.

Ps. be aware there are some issues on asp.net when using url rewrite when using cookieless session, and the rewritten url is deeper than the original page, just like the one you have. (/abc/apage vs. /db?). The issue is right into the source code of the framework, there are workarounds but that's a whole subject (with tradeoffs :( ... you might want to have them at the same level).

eglasius
A: 

I never did it, but I saw the code using Reflector and I guess you can fix it this way:

On the page:

this.Form.Action = null;

or:

this.Form.SetAttribute("action", null);

If that doesn't work, just set the path you want:

this.Form.SetAttribute("action", "ABC/123.aspx");

Diego Jancic
A: 

If you upgrade to ASP.NET 3.5 SP1, the action property is now properly recognized and can be set from codebehind.

John Sheehan