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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:43:52+00:00 2026-05-24T01:43:52+00:00

I have a security class that is called by a PageBase class (that all

  • 0

I have a security class that is called by a PageBase class (that all pages will inherit from) that will redirect the user to either the home page or the login page (depending on if they’re logged in or not), if they try and access a page they aren’t authorized to see. I want to alert the user of this by saying something like,

"You are not authorized to view this page, redirecting you"

Or something like that. I know you can call javascript from your codebehind to show an alert to the user.

In my PageBase class, (again, that all pages will inherit from), there is a common Page_Init(..) method, and when I try and call my js alert from there, nothing happens. I’ve put breakpoints in my code, and the code is being hit, but the user isn’t getting the alert. I assume this is because Page_Init is too early in the page’s lifecycle to execute js, and that that is what is causing this issue.

Is there a way around this without having to add a function to each individual page? Also, here are the two ways I have tried:

System.Web.UI.Page page = HttpContext.Current.CurrentHandler as System.Web.UI.Page;
System.Web.UI.ScriptManager.RegisterStartupScript(page, page.GetType(), "alert", "alert('You do not have access to this page. You are being redirected')", true);

and

Response.Write("<script type='text/javascript'>alert('You do not have access to this page. You are being redirected');</script>");
  • 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-05-24T01:43:53+00:00Added an answer on May 24, 2026 at 1:43 am

    The issue is NOT that there isn’t any page on the Page_Init. The problem is that the server is not sending out anything to the browser because it’s too early in the Page Lifecycle. (more coming)

    Under normal circumstances, response data is not sent to the browser until the Rendering event, even if you call Response.Write. This can often be forced by calling Response.Flush() immediately after Response.Write BUT that often has unintended consequences. In the Page_Init cycle, I think that calling Response.Flush() would probably cause you plenty of problems.

    You might be better served simply creating a static html page with the “we’re redirecting” message, and using a javascrip.SetTimeout method to count down and use javascript to redirect after a few seconds. That’s how it’s been done on the web for years. Your base class can simply redirect to this page when the user is not authorized.

    Code for the “redirect” page.

    <html>
     <head>
     <script type="text/javascript">
     function delayedRedirect(){
         window.location = "/default.aspx"
     }
     </script>
     </head>
     <body onLoad="setTimeout('delayedRedirect()', 3000)">
     <h2>You are not authorized to view this page, redirecting you</h2>
     </body>
     </html> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I build a .NET Class Library project that accesses the mshtml.HTMLDocument when called (from
I have A WCF service that has a class that inherits System.Web.Security.RoleProvider. In this
I have a class that uses a method from a bean. I'm trying to
I have a Security class that looks like this: package controllers; import play.Logger; public
I have built a User class that attempts to lookup the ID for a
I have a security consultant demanding that we implement encrypted connections to mySQL. He
Is there a way to see users that have certain security role assigned? I'm
I have a service class implemented in Java 6 / Spring 3 that needs
I'm working on a grails legacy project. A domain class called User exists. It
I have a WCF service with a security class for getting some of the

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.