views:

127

answers:

2

After I inserted the configuration below in my Web.Config

<authentication mode="Forms">
  <forms name="appNameAuth"
   path="/" loginUrl="login.aspx" protection="All" timeout="30">
    <credentials passwordFormat="Clear">
      <user name="user" password="password" />
    </credentials>
  </forms>
</authentication>
<authorization>
  <deny users="?" />
</authorization>

All requests to

Menu.aspx#fragment

are redirected to

login.aspx?ReturnUrl=/Menu.aspx

and I expected it to be redirected to

login.aspx?ReturnUrl=/Menu.aspx#fragment

How to achieve the desired behavior?

+1  A: 

That #fragment anchor tag is a client side (browser) component of the URL. It doesn't get sent to the WebServer as far as I know so the server-side has no clue about it as part the redirect.

EDIT

Can you check your IIS logs and confirm that because I'm 99% sure that that's not the case.

From a quick test on my local machine.

  1. Attempt to browse to

    http://localhost/formstest/private.aspx#test

  2. Get Redirected

    http://localhost/formstest/login.aspx?redirect=http%3a%2f%2flocahost%2fformstest%2fprivate.aspx#test

    (Notice the # is not escaped as part of the redirect url.

  3. Check IIS for first hit.

    2010-04-12 13:36:45 W3SVCxxx 127.0.0.1 GET /formstest/private.aspx 80 - DETAILS SNIPPED - 302 0 0

    (Notice the 302 Redirect and the absense of the #test token on the URL

  4. Check IIS for the redirect hit.

    2010-04-12 13:36:46 W3SVCxxx 127.0.0.1 GET /formstest/login.aspx redirect=http%3a%2f%2flocahost%2fformstest%2fprivate.aspx 80 - DETAILS SNIPPED - 200 0 0

    (There's your 200 OK HTTP Response and still no #test

Like I said, the server doesn't know anything about the #anchor. It's only on the client side regardless of whether you put it in before or after the request is made, or whether you update it with JQuery... it doesn't go to the server.

Eoin Campbell
I'm sorry, you would be right if this #fragment was changed after the page request, but in my case the #fragment is sent to the server.
Jader Dias
why the down vote? I've added more detail explaining that the anchor is NOT part of the request... ever. have a read of this, or try recreate it yourself and check the IIS logs. http://www.mikeduncan.com/named-anchors-are-not-sent/
Eoin Campbell
@Eoin You showed me the logs, but the logs are incomplete, but when I am handling the request in the `aspx.cs` file I have access to the hash via `Request.Url.Fragment`. Such property wouldn't exist if such information never reached the server.
Jader Dias
@Eoin and the problem is exactly that step 2 doesn't happen as you describe, the `Fragment` doesn't appears in the redirect parameter
Jader Dias
@Jader - if you read the XML Docs on the `Fragment` Property... it says "Gets the escaped URI Fragment"... in other words if it's not escaped and just a `#` then it won't work... anyway glad you have a solution with your URL rewriting rules...
Eoin Campbell
@Eoin but I tested it unescaped and worked
Jader Dias
@Eoin maybe the escaped doesn't refers to the `#` itself, but to the content after it
Jader Dias
A: 

The only solution I have found so far is to use a Rewrite rule to encode the # character to %23.

Thanks Claudio!

Jader Dias