Results 1 to 4 of 4

Thread: Multiple forms and authentication

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2003
    Posts
    16

    Question Multiple forms and authentication

    Hi. I'm creating a simple web application and I'm having trouble with user authentication. Please help me out.

    The application consists of three forms: login, default, and remarks. The login page asks for a username and password, sets the Context.User equal to the authorized user, and redirects the page to default.aspx. The load event of default.aspx checks first if the Context.User.Identity.IsAuthenticated is true before showing the page. If false, the user will be redirected to the login page.

    At the 'default' page, there's a hyperlink that opens the 'remarks' page in a new window (using javascript window.Open).

    The problem is this: Whenever I show the remarks page using window.Open(), the value of the Context.User.Identity.IsAuthenticated becomes false and the value of the Context.User.Identity.Name is "". It seems that it uses a different Context.User object.

    What can I do about this? Basically, I need the remarks page to point to the same Context.User as the default page's.

  2. #2
    Member
    Join Date
    Aug 2002
    Location
    Pakistan
    Posts
    32
    Since you are opening a new window thus the authenticated value be equal to false.

    What in my opinion you shall try is to store the authenticated username and password in sessions. Retrieve these values in the remarks page and there set the values of the user again and authenticated == true.

    Hope it gives you an idea ....

    Regards,

    Harris Moin
    You'll get life just for once so don't waste it .......

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2003
    Posts
    16
    i tried using sessions but it doesn't seem to work as well. here is what I did:

    1. After the user logs on and is validated, i added a new session:

    Session.Add("currentLogin", txtUserName.Text)

    2. At the Load event of 'remarks.aspx', I attempted to get the session:

    string currentLogin = Session.Item("currentLogin");

    When I use Response.Redirect() to open the remarks page, there's no problem. The currentLogin variable gets the value of the session. However, when I open the remarks page in another window (using javascript window.Open), the value of currentLogin is "".

    Any ideas?

  4. #4
    Member
    Join Date
    Aug 2002
    Location
    Pakistan
    Posts
    32
    Hi again...

    Actually the issue you are facing is that you are calling the remarks page from the client side. And the client side is not able to read sessions.

    First of all what you shall do is debug your project and check whether it goes to the server side your on load function when you open it in the new window. As sometimes i think it needs enablesessionstate property set to true.

    Secondly if that doesn't solve your problem then you shall open the remarks page not from javascript but from code behind. Usually for that we play a little trick. That is make a function in javascript which has the text of window.open(). and call this function from the code behind.

    For that you might need a label on your default page with no text and on the click write the following code.

    Label1.Text = "<script language='javascript'>functionname()</script>";

    Hope that helps,

    Regards,

    Harris Moin
    You'll get life just for once so don't waste it .......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width