Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a perfectly working asp.net web application. i want to tweak things a little bit. i have given a specific to my session. Hence, users are redirected to login page after session expires. What i want to do though, is to tell them why they have been redirected to login again(i.e session out). How do i achieve it. Note. if the login page is visited for the first time, the error message is invisible. it only becomes visible when the page is loaded as a result of session time out.

What I have tried:

Cant think of any for now apart from redirecting users to login page when session expires
Posted
Updated 11-Nov-16 2:49am

There's no foolproof way of doing this as the web is stateless, but you could check the http referer property to see if the request has been instigated from another page. To be honest though I just wouldn't bother. People are used to being dumped to a login screen when their login expires. I'd be more inclined to spend the effort using cookies to manage authentication so their authentication can last beyond the session and only ends when they choose to logout or close their browser.
 
Share this answer
 
while redirection add a query string to the url.
C#
Response.Redirect("Utility.aspx?SomeKey=1");

and check for the query string in the login page page_load event , based on the value you shall show/hide the message

C#
protected void Page_Load(object sender, EventArgs e)
        {
            lblMessage.Visible = false;
            var value = Request.QueryString["SomeKey"];
            if (value != null)
                lblMessage.Visible = true
 
Share this answer
 
Comments
Mcbaloo 14-Nov-16 3:08am    
Worked perfectly. Thanks
Karthik_Mahalingam 15-Nov-16 0:31am    
welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900