Default ASPX form in virtual directory?

Discussion in 'ASP .Net' started by Usenet User, Sep 17, 2008.

  1. Usenet User

    Usenet User Guest

    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!
     
    Usenet User, Sep 17, 2008
    #1
    1. Advertising

  2. Usenet User

    George Guest

    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.


    "Usenet User" <> wrote in message
    news:...
    > 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!
    >
     
    George, Sep 18, 2008
    #2
    1. Advertising

  3. Usenet User

    Norm Guest

    On Sep 17, 10:05 pm, "George" <> wrote:
    > 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.
    >
    > "Usenet User" <> wrote in message
    >
    > news:...
    >
    > > 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!


    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
     
    Norm, Sep 18, 2008
    #3
  4. Usenet User

    Usenet User Guest

    On Thu, 18 Sep 2008 01:05:04 -0400, "George" <>
    wrote:

    >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!
     
    Usenet User, Sep 18, 2008
    #4
  5. Usenet User

    George Guest

    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.


    "Norm" <> wrote in message
    news:...


    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
     
    George, Sep 19, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gan
    Replies:
    1
    Views:
    9,781
    Todd Derksen [MSFT]
    Nov 4, 2003
  2. ABC
    Replies:
    2
    Views:
    2,341
  3. yousry
    Replies:
    0
    Views:
    945
    yousry
    Apr 12, 2006
  4. =?Utf-8?B?SmVmZiBCZWVt?=

    physical path to virtual path under virtual directory

    =?Utf-8?B?SmVmZiBCZWVt?=, Aug 1, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    1,047
    Eliyahu Goldin
    Aug 1, 2007
  5. rockdale

    include virtual in virtual directory?

    rockdale, Sep 3, 2008, in forum: ASP General
    Replies:
    3
    Views:
    445
    rockdale
    Sep 4, 2008
Loading...

Share This Page