4

We are using asp.net 4.0 and routing with web forms to create friendly urls.

The routing is working fine except that the correct "action" value is not being assigned to the form element in the master page for any route that has multiple levels.

For example, the route ( customer/{customerid} ) when browsed to with .../customer/12345 only displays 12345 in the "action" attribute of the form. The issue with this is that it isn't complete and any postback fails and gives an error "The HTTP verb POST used to access path is not allowed" If I updates the action as "customer/12345" (using Firebug), the postback works fine.

It even errors when using static routes like customer/customer, it only puts "customer" and not "customer/customer" as the action value of the form. Basically, only putting the last piece of the route into the action attribute instead of the whole route. Why?

Any ideas on how to correct this?

Raj
  • 2,642
  • 3
  • 22
  • 20
  • 1
    I further found that I can work around by overiding the form action as [form1.Action = Request.Url.PathAndQuery;] in Page_Load event. Should there be a better solution? – Raj Mar 11 '11 at 12:12
  • https://stackoverflow.com/questions/33307491/asp-net-url-loses-page-path-on-postback – Alexander Brattsev Sep 18 '18 at 08:40

2 Answers2

2

You can work around this by overiding the form action as form1.Action = Request.Url.PathAndQuery;]in the Page_Load event

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
Raj
  • 2,642
  • 3
  • 22
  • 20
0

See this related Topic. It uses Request.RawUrl instead of Request.Url.PathAndQuery, which seams to return the same value.

Community
  • 1
  • 1
spaark
  • 701
  • 10
  • 17