[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Forms Authentication -- Why 302 on Login form?

Asked by farsight in Programming for ASP.NET

Tags: 302

[Long, but I hope the solution is simple.]

I believe this code was working in the past (perhaps a year ago).  Now, I've come back to it and it doesn't work.  I've cut it back to the minimum, and it still doesn't work.  I suspect I'm just missing or forgetting some very simple little thing.

Client and server are both running on my dev machine, at localhost 127.0.0.1.
The dev machine I'm working on has:
    Window 2000 Professional (Win2KPro)
    Microsoft-IIS/5.0
    .NET CLR 1.1.4322
    Internet Explorer 6.0 (MSIE 6.0)
I am running Norton AntiVirus and ZoneAlarm Pro.

The problem is that the user authentication doesn't seem to "stick" from the Login form back to the Redirect URL.  It's as if the user never was authenticated.

I've got two web pages, (1) WebForm1.aspx, which requires an authenticated user, and (2) Login.aspx, the login form.

I test using this use case:
(A) With WebForm1.aspx set as the start page, start the application. It goes to WebForm1.aspx ...
(B) but there is no authenticated user, so it is automatically redirected to Login.aspx.
(C) In the Login.aspx, enter user and password: "guest", "guest", and click the Login button to POST it back to Login.aspx
(D) The Login page authenticates the user, then calls RedirectFromLoginPage, so ...
(E) ... it goes to WebForm1.aspx ...
(F) ... but it (INCORRECTLY) is automatically redirected to Login.aspx, even though the login was authenticated.
What's going on here?

Can you help get this working?

I've added some Debug.Writeline() statements to document the path taken through the code, matching steps A thru F.  They produce the following output.

Application_AuthenticateRequest: /LoginX/WebForm1.aspx
Application_AuthenticateRequest: /LoginX/Login.aspx?ReturnUrl=%2fLoginX%2fWebForm1.aspx
Application_AuthenticateRequest: /LoginX/Login.aspx?ReturnUrl=%2fLoginX%2fWebForm1.aspx
Authenticated: guest, guest
Application_AuthenticateRequest: /LoginX/WebForm1.aspx
Application_AuthenticateRequest: /LoginX/Login.aspx?ReturnUrl=%2fLoginX%2fWebForm1.aspx


The http://localhost/LoginX/Trace.axd shows info below.
Note that the status code is 302 when the Login.aspx is POSTed.  Why is this?  Why would it be 200 the first time, for the GET, then 302 for the second time?  I know that you can set specific access for different verbs in web.config, but I haven't done that.  See the web.config listing below.

No. Time of Request File Status Code Verb
1 3/16/2005 3:54:48 AM /WebForm1.aspx ... 302 GET View Details
2 3/16/2005 3:54:50 AM /Login.aspx ...... 200 GET View Details
3 3/16/2005 3:58:32 AM /Login.aspx ...... 302 POST View Details
4 3/16/2005 3:58:32 AM /WebForm1.aspx ... 302 GET View Details
5 3/16/2005 3:58:32 AM /Login.aspx ...... 200 GET View Details

(Note: If you enter anything but guest, guest, the login page will try to redirect to default.aspx, which doesn't exist, so you'll get a "404 Not Found" error.  That's as expected.)

If needed, I can easily provide exact instructions and code listings to create the project.  It's already written up, but it's a few pages long.

--- listing of web.config ---
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
      <system.web>
            <compilation defaultLanguage="vb" debug="true" />
            <customErrors mode="RemoteOnly" />

            <authentication mode="Forms">
                  <forms name=".ASPXCOOKIEAUTH2"
                        path="/"
                        loginUrl="Login.aspx"
                        protection="All"
                        timeout="60">
                        <credentials passwordFormat="Clear">
                              <user name="guest" password="guest" />
                        </credentials>
                  </forms>
            </authentication>

            <authorization>
                  <allow users="*" /> <!-- Allow all users -->
            </authorization>

            <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
            <sessionState
                        mode="InProc"
                        stateConnectionString="tcpip=127.0.0.1:42424"
                        sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
                        cookieless="false"
                        timeout="20"
            />
            <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
      </system.web>
 
       <!-- Deny unauthenticated users to WebForm1. -->
    <location path="WebForm1.aspx">
        <system.web>
            <authorization>
                <deny users="?" />
            </authorization>
        </system.web>
    </location>

</configuration>
--- end listing of web.config ---
[+][-]03/16/05 06:25 PM, ID: 13561605Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Programming for ASP.NET
Tags: 302
Sign Up Now!
Solution Provided By: laotzi2000
Participating Experts: 1
Solution Grade: A
 
[+][-]03/16/05 05:29 PM, ID: 13561409Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/16/05 05:53 PM, ID: 13561489Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/16/05 06:02 PM, ID: 13561524Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/16/05 06:15 PM, ID: 13561577Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/16/05 06:56 PM, ID: 13561732Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92