Default ASPX form in virtual directory?

  • Thread starter Thread starter Usenet User
  • Start date Start date
U

Usenet User

Platform: IIS 5 or 6, ASP .NET 1.1

I can configure default page for my virtual directory and "hide" that
page from users. For example, if I have an ASPX from called
MyPage.aspx, I can make it default, so it can be omitted from URL:

http://mysite/mydir/

instead of

http://mysite/mydir/MyPage.aspx

The problem I see is that even if the user uses the "short" URL, on
the postback he gets redirected to the full URL. This is because
"MyPage.aspx" is used a the form's target tag in the generated HTML
code. Such behavior defies the purpose and also, I believe, messes up
the ViewState on the first postback due to redirect.

Is there a good way to avoid the above issues and make sure the the
"short" URL is preserved throughout postbacks?

Thanks!
 
There is no redirect involved so nothing messes up the ViewState.
IIS silently replaces the request http://mysite/mydir/ with
http://mysite/mydir/MyPage.aspx and there is no way for ASP.NET to know that
the short url was hit.
Then ASP.NET populates the action property of the <form> with currently hit
page i.e. default.aspx

There is no way to fix it in ASP.NET 1.1 (May be there is but a tricky one
and i do not know it).
Starting ASP.NET 3.5 you can specify empty action property of the <form> and
then ASP.NET will not override it.


George.
 
There is no redirect involved so nothing messes up the ViewState.
IIS silently replaces the requesthttp://mysite/mydir/withhttp://mysite/mydir/MyPage.aspxand there is no way for ASP.NET to know that
the short url was hit.
Then ASP.NET populates the action property of the <form> with currently hit
page i.e. default.aspx

There is no way to fix it in ASP.NET 1.1 (May be there is but a tricky one
and i do not know it).
Starting ASP.NET 3.5 you can specify empty action property of the <form> and
then ASP.NET will not override it.

George.

George,

I have a similar situation involving url rewritten links. ("/Item/
1.aspx" = "/Item.aspx?ItemID=1") Postbacks will automatically post to
the "internal" page, not the rewritten one. Can you provide more
information about this feature in APS.NET 3.5? Thx in advance.

-Norm
 
There is no redirect involved so nothing messes up the ViewState.

Sorry, by redirect I meant that the original short URL is replaced by
the full URL via form's action, so on the first postback the user goes
to a different URL. The ViewState *can* be affected. I have a form
that erases itself on the first postback, if the short URL is used.
Not sure why this is happening. Just built another, simpler form, and
that one behaves correctly...
IIS silently replaces the request http://mysite/mydir/ with
http://mysite/mydir/MyPage.aspx and there is no way for ASP.NET to know that
the short url was hit.

Ouch! That is really the barrier... Indeed, both Request.Url and
Request.RawUrl contain the actual page name, even if the short URL was
used.
Then ASP.NET populates the action property of the <form> with currently hit
page i.e. default.aspx

There is no way to fix it in ASP.NET 1.1 (May be there is but a tricky one
and i do not know it).

Well, SmartNavigation="true" seem to help (see
window.__smartNav.attachForm in
aspnet_client\system_web\1_1_4322\SmartNav.js), but I would not rely
on that 100%. The same stubborn form mentioned above does not work as
intended.

In theory, if the real URL the user used was discoverable, form's
action could be overridden in Page rendering events somewhere. But it
would be too much hassle, I think. (One "hacky" way to pass the URL
to the server is to grab window.location.href in Javascript and store
it in a server-side hidden control.)
Starting ASP.NET 3.5 you can specify empty action property of the <form> and
then ASP.NET will not override it.


George.

Thanks!
 
Yes, it's a common problem with UrlRewriting.
There are several ways to solve the problem.

I had described the solution in my blog post
http://georgeplusnet.blogspot.com/2008/06/perfect-aspnet-application-part-7.html

I would recommend to go through all 7 posts. You might find them
interesting.

In ASP.NET 3.5 <FORM> object has a property "action" now which will not be
overwritten by ASP.NET. So you can simply set it to "" it will generate
<from action=""> HTML.
So put it into your OnLoad event this.Page.action="";

Also I believe you can set it declaratively in the page itself
<form action="" runat=server>


George.




George,

I have a similar situation involving url rewritten links. ("/Item/
1.aspx" = "/Item.aspx?ItemID=1") Postbacks will automatically post to
the "internal" page, not the rewritten one. Can you provide more
information about this feature in APS.NET 3.5? Thx in advance.

-Norm
 
Back
Top