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 7961763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:08:28+00:00 2026-06-04T05:08:28+00:00

I have code in my ASP.NET master Page_Init event page that checks if a

  • 0

I have code in my ASP.NET master Page_Init event page that checks if a user is authorized to be on the content page, and if not redirects them to the login page. This code works fine as far as the check itself.
However, I have discovered that the content Page_Load event still fires after the above redirect.
This is causing a problem on pages that assume the user is logged in and certain variables are set.

This is the master page code (simplified)

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
...
            If Access_Level > User_Level_ID Then
                Response.Redirect("~/login.aspx", False)
            End If

    End Sub

The above test works fine, and the redirect line is executed, but doesn’t take effect before the code below is fired and executes.

This is the content page code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim Rec_IDs As New List(Of String)
    Rec_IDs = Session("Rec_IDs")
    lblCount.Text = String.Format("You have {0} records in your cart", CType(Rec_IDs.Count, String)) 'this gives an error if Session("Rec_IDs") is null
End Sub

I realize I can put code in each of my content pages to check if a user is logged in / authorized, but I wanted to control it all from one location if possible.

Am I doing something wrong? I’ve read so many pages that say the master page is the place to do the check.

Thanks. 🙂

  • 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-04T05:08:30+00:00Added an answer on June 4, 2026 at 5:08 am
        Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    ...
                If Access_Level > User_Level_ID Then
                    Response.Redirect("~/login.aspx", True)
                End If
    
        End Sub
    

    Using Response.Redirect(“~/login.aspx”, True) will terminate the current page processing & redirect to desired page.

    Though it is recommended to use “Response.Redirect(“~/login.aspx”, False)” but this will not terminate page execution. It will redirect after current page processing end.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in a ASP.NET master page: <div id=hyperlinkimage><asp:HyperLink ID=SomeHyperLink runat=Server
I have a master page in my asp.net MVC project, which has code like
I have an ASP.NET MVC site (Master Page + Content pages). On the master
I have this code in my ASP.NET MVC project master page: <% switch(Request.Browser.Browser) {
I have an asp.net website that has a master page and multiple normal pages.
The Scenario I have an ASP.Net Web Project that uses a master page. This
I have the following code in my Site.Master page of an almost empty ASP.NET
I have this code in my ASP.NET application written in C# that is trying
I have a code base that has been used as an ASP.Net web application.
I have a master page that divides the main content into two areas. 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.