Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:54:47+00:00 2026-06-10T17:54:47+00:00

I would like to redirect users to a custom page if their session has

  • 0

I would like to redirect users to a custom page if their session has expired.

On PageLoad
If Session("OrgID") = Nothing Then
    Response.Redirect("SchoolLogin.aspx?schoolID="+[schoolid])
End If

I can store the schoolID in a hidden field on every page, but this doesn’t seem very elegant. I thought to try using the hidden field in a user control that I do have on every page, but the user control PageLoad fires after the main PageLoad so I’d get an error prior to checking for session expiration. Is there a common solution for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:54:49+00:00Added an answer on June 10, 2026 at 5:54 pm

    You can use QueryString, ViewState (ASP.NET’S built in hidden field) or setting it as a cookie value.

    I don’t know enough about your scenario. The best I can offer is an example of how I deal with (what I am guessing) is similar to your situation.

    Create a base class for all your page classes to inherit from (more here oldy but goody https://web.archive.org/web/20211020133935/https://www.4guysfromrolla.com/articles/041305-1.aspx), Add your SchoolId property to it. This is in c# I appologise, unfortunately VB.NET syntax literally makes my teeth jangle. It shouldn’t be too hard to translate though as this is pretty basic stuff.

    Using QuertString, you would need to test for -1 and redirect in that case.

    public class BasePage : System.Web.UI.Page
    {
        public int SchoolId
        {
            get
            {
                if (Request.QueryString["schoolId"] != null)
                {
                    return Convert.ToInt32(Request.QueryString["schoolId"]);
                }
                else
                {
                    return -1;
                }
            }
        }
    }
    

    Using ViewState

    public class BasePage : System.Web.UI.Page
    {
        public int SchoolId
        {
            get
            {
                if (ViewState["schoolId"] != null)
                {
                    return (int)ViewState["schoolId"];
                }
                else
                {
                    int schoolId = someDataLayer.SelectUsersSchoolId(User.Identity.Name);
                    ViewState["schoolId"] = schoolId;
                    return schoolId;
                }
            }
        }
    }
    

    Using cookies (More here) http://msdn.microsoft.com/en-us/library/aa289495(v=vs.71).aspx

    public class BasePage : System.Web.UI.Page
    {
        public int SchoolId
        {
            get
            {
                if (Request.Cookies["schoolId"] != null)
                {
                    return (int)Request.Cookies["schoolId"].Value;
                }
                else
                {
                    int schoolId = someDataLayer.SelectUsersSchoolId(User.Identity.Name);
                    Request.Cookies["schoolId"].Value = schoolId;
                    Request.Cookies["schoolId"].Expires = DateTime.Now.AddDays(1);
                    return schoolId;
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to make it possible to redirect users from a site to
I would like to download a .CSV and redirect the user to another page.
I would like to redirect visitors to a login page with added parameters (based
Quick question. I am writing a website and would like to redirect users to
I would like to redirect users that use a wrong querystring in the URL
I would like to redirect my users to specific location areas in my website,
I would like for my app to redirect users encountering a JSF ajax error
I would like to redirect my user to another domain. For example: my site
I would like to redirect all requests, that coming to www.website.com/whatever to the variant
I would like to redirect the Debug stdout stream to a textblock. Is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.