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

  • Home
  • SEARCH
  • 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 8245919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:20:31+00:00 2026-06-07T22:20:31+00:00

I’m fixing my friend’s codes. And I have a problem with session value in

  • 0

I’m fixing my friend’s codes. And I have a problem with session value in masterpage.
I’m checking session is null or empty in masterpage and if it’s null go to login page.
But other pages that created by masterpage never works.

if (Session["user"] != null && Session["user"] != "")
{ }
else
{
    Response.Redirect("/Account/Login.aspx?link=" + System.Web.HttpContext.Current.Request.Url.PathAndQuery);
}

I tried with Session[“user”].ToString() but same result.

And the otherpages have a other controls via this session so it always give error if you are not login.

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    MaintainScrollPositionOnPostback="true" CodeFile="document.aspx.cs" Inherits="document" %>
  • 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-07T22:20:34+00:00Added an answer on June 7, 2026 at 10:20 pm

    Based on this:

    But session control in back.master’s page_load fire after default.aspx page_load so it gives me error the “session is null”

    The root problem here is simple… You need to fully understand the ASP.Net page life-cycle

    Take a quick look:

    enter image description here

    Basically your following assumption is wrong:

    Then i create normal aspx page which name is default.aspx and is derived by back.master

    From MSDN:

    Master pages behave like child controls on a page: the master page Init event occurs before the page Init and Load events, and the master page Load event occurs after the page Init and Load events

    Sadly an ASP.Net does not derive from a Master Page Why? because a Master Page is treated as a control so what really happens is that the master page is a child control of the Page

    Alternatives:

    • Since you are checking if the user is authenticates, it would be better if you rely on the ASP.Net authentication and authorization API

    Workarounds (if you insist to use your own authentication mechanism):

    • (Best recommendation) Create a custom HttpModule and check the Session object there. I think the event that best fits your needs is the: Application_AuthenticateRequest. This is a full list of events you can choose from: (BTW there’s no need to create a new HttpModule, you could subscribe to events using the Global.asax file of your web application, use an HttpModule only if you would like to encapsulate the logic to reuse it)

      • Application_BeginRequest.
      • Application_AuthenticateRequest.
      • Application_PostAuthenticateRequest.
      • Application_DefaultAuthentication.
      • Application_AuthorizeRequest.
      • Application_PostAuthorizeRequest.
      • Application_ResolveRequestCache.
      • Application_PostResolveRequestCache.
      • Application_MapRequestHandler. Fired only when the server is running IIS 7 in Integrated Mode and at least >Net Framework 3.0
      • Application_PostMapRequestHandler.
      • Application_AcquireRequestState.
      • Application_PostAcquireRequestState.
      • Application_PreRequestHandlerExecute.
      • The page event handler is executed. (refer to the page life cycle)
      • Application_PostRequestHandlerExecute.
      • Application_ReleaseRequestState.
      • Application_PostReleaseRequestState
      • Application_UpdateRequestCache.
      • Application_PostUpdateRequestCache
      • Application_LogRequest. Fired only when server is IIS 7 Integrated Mode and at least .Net Framework 3.0
      • Application_PostLogRequest. Fired only when server is IIS 7 Integrated Mode and at least .Net Framework 3.0
      • Application_EndRequest.

      For more info:

      • ASP.NET Application Life Cycle Overview for IIS 5.0 and 6.0

      • ASP.NET Application Life Cycle Overview for IIS 7.0

    • Create a generic page inheriting from Page and place the check code there in the PreLoad or Load event, both events would work and finally inherit all your pages from this page

    • (Not recommended) If you want to encapsulate the check inside the Master Page, you could use the Init event

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have two tables with like below codes: Table: Accounts id | username |
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.