<base> tag and PostBack

  • Thread starter Thread starter SJ
  • Start date Start date
S

SJ

Hi,

I have a problem with the HTML <base> element, URL re-writing and Postback.
We are using URL re-writing on the server, and I'd like to use the base
element to make the URLs in the ASPX pages more maintainable. Otherwise, we
have to manually output the application root eg. src="<%= AppRoot %>". This
is cumbersome and hard to maintain.

However, there seems to be no way - apart from a client-side script - to
rewrite the action attribute of the form to handle the full path to the
file. Does anyone know if there is a better way to achieve re-writing of the
action attribute so that it automatically handles the full path?

Thanks

Simon
 
Hi Simon,

I am not very clear on what concern you have. If you want to change the
Action attribute of the Form tag, I have to tell you that in ASP.NET, a web
form can only be submitted to itself. As a sequence, the Action attribute,
by default was set to the current web page itself, and in such case, no
full or absolute path is necessary.

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Jacob,

Thanks for your reply. The problem is that the browser interprets the URL
specified in the action attribute with respect to the base tag - it's as if
the HREF attribute of the base tag is physically inserted in the action
attribute. So, if we have the following tags in an ASPX
mybase/myapp/default.aspx:

<base href="http://mybase">
<form action="default.aspx">

the form data will be POSTed to http://mybase/default.aspx - which is wrong.
I could make the base http://mybase/myapp but that invalidates the point of
using base.

What I'd like to do is to override the action attribute, replacing it with a
fully qualified path - or have ASP.NET do that for me!

Thanks

Simon
 
Hi Simon,

Thanks for your clarification.

To implement your task, we can override the Render event of the base web
page, where we can replace the action with the full qualified URL. For
example,

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim sb As StringBuilder = New StringBuilder()
Dim sw As StringWriter = New StringWriter(sb)
Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
MyBase.Render(htw)
Dim html As String = sb.ToString().Replace("dropdownlist.aspx",
"http://localhost/dropdownlist.aspx")
writer.Write(html)

End Sub

Here, we replace the dropdownlist.aspx, which the name of current web page.

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top