redirecting to loginpage on session timeout

Last post 05-14-2008 5:33 AM by Benson Yu - MSFT. 29 replies.

Sort Posts:

  • Re: redirecting to loginpage on session timeout

    05-08-2008, 7:20 AM

    Is it showing any error.Post the section of code from web.config where you have given the sessionstate details. Also did you try refreshing your page after 2 minutes.

  • Re: redirecting to loginpage on session timeout

    05-08-2008, 7:29 AM
    • Loading...
    • blurearc
    • Joined on 04-25-2008, 11:15 AM
    • Mumbai India
    • Posts 530

    It will work.. when you do next page request on this page..

    do one thing

    out one button on the page..

    and after 2 mins.. click this button..

    it will give a postback to the page..

    and code will go to page load..

    here it will read that there is no session..

    and it will redirect to login..

    but in any case it will not do it automatically.. unless u do a page request..

    :)

    "Mark as answered if you feel this helps you"
    "Curiosity is Bliss"
    Regards,

    Ravi Kant Srivastava
    (Sr. Software Engineer)
    Connexxions Business
    Mumbai
    INDIA
  • Re: redirecting to loginpage on session timeout

    05-08-2008, 7:42 AM

    I have tried like whatever you said,but it is not working.

    plzzz help me?

    Chithra_Iyer
  • Re: redirecting to loginpage on session timeout

    05-08-2008, 8:02 AM

    Hi chitra

    I am not sure why it is not working can u please post your codes and web.config settings here ?

  • Re: redirecting to loginpage on session timeout

    05-08-2008, 10:22 AM

    Set the value of timeout of session state  to some time in the web.config file

    then check the  session in page load, id it is blank , redirect to your login page

     
    <sessionState  timeout="10" ></sessionState>

    ======================================
    Regard,
    Pradeep Sahoo
    Sr. Sofware Developer
    Don't forget to click "Mark as Answer" on the post that helped you.
  • Re: redirecting to loginpage on session timeout

    05-09-2008, 12:07 AM

    hi, my web config code is

    <?xml version="1.0"?><configuration>

     

    <
    appSettings>

     

    <add key="MyConnectionString" value="Data Source='EKOPSA02\SQLEXPRESS';Initial Catalog=DefectTracker(Test);User ID=sa;Password=sql"/>

    </appSettings>

    <connectionStrings/>

    <system.web><sessionState mode="InProc" timeout="2" >

     

    </sessionState>

    <compilation debug="true">

     

    </compilation>

    <authentication mode="Forms">

     

    </authentication>

    <authorization> <deny users="?" />

    </authorization>

    </system.web>

    </configuration>

     

    global.asax file code is

    void Session_End(object sender, EventArgs e)

    {

    Response.Redirect("SessionExpired.aspx");

    }

     

    why it is not working?

    plzz help me

    Chithra_Iyer
  • Re: redirecting to loginpage on session timeout

    05-09-2008, 12:28 AM

    Hi,

    In global.asax file i have given like this also.

    void Session_End(object sender, EventArgs e)

    {

    if (HttpContext.Current.Session.SessionID == null)

    {

    Response.Redirect(
    "SessionExpired.aspx");

    }

    }

    then the control is going to

    void Application_Error(object sender, EventArgs e)

    {

    }

     

    plzz help me ASAP

    Chithra_Iyer
  • Re: redirecting to loginpage on session timeout

    05-09-2008, 7:10 AM

    Hi Chitra

    Remove the code form seesion_end. It is not always dependable.

    In your main page's page_load event check for seesion

    protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Username"] == null)
            {


                Response.Redirect("login.aspx");

            }


           

        }

  • Re: redirecting to loginpage on session timeout

    05-09-2008, 7:24 AM

    Hi,

    I have tried this way also.

    I have put break point,but the control is not comming to that point(where i have placed your code in the load event of main page).

    even the control is not comming.why?

    my dought is how the control will come there?.it is not loading.that page is still idle?.then how its load event will get fired?.

    even the control is not coming.whether i have to write any code to refresh the page?.plzzz help me ASAP

    cheers

    Chithra_Iyer
  • Re: redirecting to loginpage on session timeout

    05-09-2008, 7:35 AM

    Hi,

    I will get the login.aspx page when i refresh(or control goes to the load event or when i clicl any button).ok

    no problem..but the main problem is

    i am using three frames in the mainpage.aspx

    left frame,heading frame and content frame.

    heading frame contains headins,left frame contains tre view controls and the content frame displays the aspx pages dynamically depends on the click happening in the tree view.So all pages are displaying inside the content page.aspx.

    so this login page is also displaying inside this frame.

    Actually i want to open that as a separate page.

    what to do?

    plzzzzzzzzzz..any ways?

    cheers

    Chithra_Iyer
  • Re: redirecting to loginpage on session timeout

    05-09-2008, 7:46 AM
    • Loading...
    • blurearc
    • Joined on 04-25-2008, 11:15 AM
    • Mumbai India
    • Posts 530

    then do not re direct..

    do this.. 

    if(SessionCheck.Session("SessionVal")==false)
    
    {
    
        Response.Write("<script type='text/javsascript'>window.parent.location.href='login.aspx'</script>")
    
    }
    
     
    "Mark as answered if you feel this helps you"
    "Curiosity is Bliss"
    Regards,

    Ravi Kant Srivastava
    (Sr. Software Engineer)
    Connexxions Business
    Mumbai
    INDIA
  • Re: redirecting to loginpage on session timeout

    05-09-2008, 8:16 AM

    hi,

    this is also not working.

    the page is displaying inside the frame.

    anyway i have resolved this problem with window.showdialog() in javascript.

    then one more problem,

    it will open a dialogue window,but it is not closing the existing application.

    How can i close existing application and from where i have to call.

    in load event my code is,

    protected void Page_Load(object sender, EventArgs e)

    {

    string jscript = ("<script>window.showModalDialog('SessionExpired.aspx','status:no;dialogWidth:90%;dialogHeight:90%;dialogHide:true;help:no;scroll:no');</script>");

    this.RegisterStartupScript("Startup", jscript);

    }

    plzzz help me

    Chithra_Iyer
  • Re: redirecting to loginpage on session timeout

    05-09-2008, 9:02 AM
    • Loading...
    • blurearc
    • Joined on 04-25-2008, 11:15 AM
    • Mumbai India
    • Posts 530

     

     
     Hello now i am getting little confused.

    so lets do one thing i will draw your page using some characters and tell me if am on the right track

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    |          ++++++++                       
    |          +            +
    |          +            +
    |          +            + 
    |          + ++++++
    |
    |
    |
    |
    |--------------------------------------------------------------------------------------------------------------------------------------------------------------------

    now above is your page with one I frame. If i am right till now then let's moive forward
    Now you have 3 iframes like this one.. which i created using "+".
    I again I am right then you are now showing your data in these iframes.
    and on session out you need to redirerct eveny thing to login.aspx in on the main browser not on the iframe.

    NOW first tell me u are using Iframe or Frames using framesets. if u r using iframe then

    the code which i gave you it will work.. or do this...

    use this code in your iframe.

    <script type="text/javascript">

     

    function checkLogout()

    {

    if(typeof(logout)=="string")

    {

    if(logout=="logout")

    {

    window.parent.location=
    "login.aspx";

    }

    }

    }

     

    </script>

    now call this method in body tag

    <body onload="ckeckLogout()">

    now in your codebehind

    if session is false do this

    Response.Write("<script='type/javascript'>var logout='logout';</script>")

    Hope this will work for you.

    :)

    "Mark as answered if you feel this helps you"
    "Curiosity is Bliss"
    Regards,

    Ravi Kant Srivastava
    (Sr. Software Engineer)
    Connexxions Business
    Mumbai
    INDIA
  • Re: redirecting to loginpage on session timeout

    05-10-2008, 12:13 AM

    HI,

    thanks a lott...but not working getting an error in <body onload="ckeckLogout()">

    like "jscript error,object expected".why it is like this?

    .lots of doubts.

    my maipage.aspx contains 3 iframes.like this

    ------------------------------------------------
    iframe1(for heading)
    ----------------------------------------------
    |            |
    |frame2  |
    |            |
    |  for      |
    treeview |      frame3(for displaying pages dynamically)
    |           |
    |           |
    |           |

    Then,suppose,currently one page is displaying in frame3,in frame 2 treeview,so when session expires when i give all the code provided yesterday,the login page will be displayed in frame3 only.still frame 2 and frame1 are displaying their contents.

    lzz check why the error is comming with the last provided code.

    i have given the javascript and onload function call in body tag in the mainpage.aspx

    then where i have to write the response.write code?the load event of which page ?load event of dynamic page or mainpage?

     

    plzzz help me?

    no one is here to help me

     

     

    Chithra_Iyer
  • Re: redirecting to loginpage on session timeout

    05-14-2008, 5:33 AM
    Answer