Submitting form to correct URL in ASP.net using BaseHREF

162 views Asked by At

For unavoidable design reasons, in my head tag on my top level MasterPage I have:

<base href="http://127.0.0.1/" />

The URL of the page I'm having difficulties with is:

http://127.0.0.1/store/checkout

On this content page I have the control:

<asp:Button runat="server" Text="Payment ▶" />

However when clicked, it posts the form to:

http://127.0.0.1/checkout

Which throws a 404, as it is not store/checkout as it should be.

How can I resolve this issue so that the form is posted to the correct URL, AND it must degrade gracefully so that if JS is disabled it will post correctly, which is why unfortunately I cannot accept any Javascript solutions!

1

There are 1 answers

0
Tom Gullen On

Doh! I've been struggling with this for days and have just stumbled across the answer.

On the master page I created a new method:

public void changeFormAction(string Action)
{
    MainForm.Action = Action;
}

Then from the content page I call:

Master.changeFormAction("/store/checkout");

This fixes it!