11 May 2005

ASP.Net Base Href Problem

Posted by Mikhail Esteves under: C#; Tips .

I use Base Href on all my sites. Now with ASP.NET, this is a problem — WebForms sitting in subdirectories don’t work. Let’s say you have a form /dir/register.aspx and you have a button there that does something. Clicking on the button gives you a server error because it takes you back to “/register.aspx”. The base-href tag is the reason this confusion takes place.

To solve this, the simplest way would be to call this function on Page_Load() of all webforms sitting in sub-directories:

public void FixBaseJS()
{
   string fixbasejs = @"script language=""javascript"">
document.forms[0].action = '" + this.Request["Url"] +
"?" + this.Request["Query_String"] + @"';
/script>";
   RegisterClientScriptBlock("fixbasejs", fixbasejs);
}

Remember to prefix a < mark before the script and /script tags found in the fixbasejs function above.



One Comment so far...

Oliver Boermans Says:

19 May 2005 at 11:42 am.

Clever! We are tackling the same issue here.

I’d be interested in pointers to any “complicated” solutions that work without JavaScript?

Leave a Reply

Browse

Photography

Projects

Pages

Calendar

May 2005
M T W T F S S
« Apr   Jun »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Categories

www.flickr.com

Use OpenDNS