We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Redirect to User Login Page When Session Expires

scissorhand
scissorhand asked
on
Medium Priority
1,918 Views
Last Modified: 2007-11-27
I have a main page with frames, meaning there are a few sub pages. How do I redirect the page to the login page which is only a single page when any session in the sub pages expire?
Comment
Watch Question

Commented:
What scrripting language are you using?
In asp you can do something like this instead of normal response.redirect

<%
    url = "http://www.yourdomain.com/redirectpage.asp
    response.write("<script>" & vbCrLf)
    response.write("parent.location.href='" & url & "';")
    response.write(vbCrLf & "</script>")

%>

Rgds
V

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT

Commented:
If you're using ASP .NET you can do like this:

Use the Forms authentication in .NET.

First of all, modify your web.config according to the following:

--- web.config bit start
          <authentication mode="Forms">
               <forms loginUrl="login.aspx">
                    <credentials passwordFormat="Clear">
                         <user name="user" password="pass" />
                    </credentials>
               </forms>
          </authentication>
--- web.config bit end

This creates a user with the user name user and the password pass. It also sets the login page to login.aspx.

Next, determine which pages should be protected. This bit is also placed in web.config outside of the system.web tag.

--- web.config bit start
     <location path="MyProtectedDirectory">
          <system.web>
               <authorization>
                    <allow users="user" />
                    <deny users="*" />
               </authorization>
          </system.web>
     </location>
--- web.config bit end

Now only user is allowed to see MyProtectedDirectory.

Then create a standard login page. When the user presses the login button you run the following code:

--- login.aspx bit start
        If FormsAuthentication.Authenticate(txtUser.Text, txtPwd.Text) Then
            FormsAuthentication.RedirectFromLoginPage(txtUser.Text, False)
        Else
            lblMessage.Text = "Invalid username"
        End If
--- login.aspx bit end

txtUser and txtPwd is of course your textboxes and lblMessage is a label for displaying a message back to the user.

As for question nr 2, just run this code when the user presses the logoff button:

--- logoff.aspx bit start
System.Web.Security.FormsAuthentication.SignOut()
--- logoff.aspx bit end

Now you just give your users the link to the protected page and they will be prompted to log in.

Author

Commented:
I am using ASP .NET

Author

Commented:
TheMegaLoser,
U misunderstand my question already, I want the page to be redirected to login page when the session expires, not for authentication, the page contains a few frames, but the login page is just a single page, I want to know the setting needed and the codes
Commented:
c# redirect code :

string strRedirect;
strRedirect = "<script language='Javascript'>";
strRedirect += "parent.location.href=yourloginPage.aspx';";
strRedirect += "</script>";
Response.Write(strRedirect);
Response.Flush();

Author

Commented:
This is the code to redirect the page, which I know about it. But how to link it with session expire?
CERTIFIED EXPERT

Commented:
In Global.asax.cs you have a function:

protected void Session_End(Object sender, EventArgs e)

This method is not supported if you use StateServer or SQLServer Session mode.

Commented:
if(Session("value") == "")
{
 --- above code goes here.....
}
CERTIFIED EXPERT

Commented:
Split between Vinod_nk and me perhaps? Vinod_nk tells how to achieve the redirect and my answer tells when to do it.
CERTIFIED EXPERT

Commented:
Strange split between Vinod_nk & Vinod_nk?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.