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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:39:57+00:00 2026-05-16T22:39:57+00:00

Update: I can’t delete this question, because the answer has been upvoted, yet it

  • 0

Update: I can’t delete this question, because the answer has been upvoted, yet it is not at all the answer to what I’m asking. I’d like to delete this, as it has been a week with no answer, and it’s just dragging down my accept %. Thanks.

I have a strongly typed master page that includes information that is based on the currently authenticated user’s UserId:

(Guid)Membership.GetUser().ProviderUserKey

Every other normal action/view would require the user to be authenticated prior to it being viewed, which means the user’s information is guaranteed to be available.

The problem is, I’m only getting null reference exceptions when I attempt to access the user’s info. from the site’s master page. I’m guessing this is because there isn’t such thing as an [Authorize] attribute that applies to master pages.

Do I have this wrong? Is there another possible cause?

Simple example:

My site’s various pages all use a view model object that inherits the master page view model:

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<Models.MasterViewModel>" %>

the authenticated user object is a property of this base view model. All pages require authentication, so anyone who isn’t is redirected to the login view, which has been working flawlessly. So a simple attempt to make use of a user’s property in a view is thus:

<%= Model.UserName %>

which I’ll put in one of the views, as well as in the site’s master view.

When the user is already authenticated, all works as it should, with the UserName being printed twice on the page. When the auth ticket is expired, or a new user comes along however, the page will not redirect to the login, but instead generate an exception that complains of a null reference coming from the <%= Model.UserName %> in the master view.

When I remove the <%= Model.UserName %> from the master view, and leave it in the normal view, it redirects as it should, without throwing the error.

I hope this is somewhat more clear.

Edit:

Maybe someone could offer a better way to access the authenticated user’s information in the master page?

Edit #2:

I would be very interested to see any example of an authenticated user’s info being accessed in the master page…this is a real head-scratcher for me.

Update:

I haven’t accepted the answer because I’m quite familiar with how I can test whether or not a user is authenticated. I am curious to know why no redirection to the login page is taking place.

  • 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-16T22:39:57+00:00Added an answer on May 16, 2026 at 10:39 pm

    The only way i manage to reproduce this error is if i add the violating codeblock to a masterpage that is referenced from pages that does not require auth, then look at’em without signing in.

    If your masterpage is not used on your logon-page, it could indicate something else is not entirely in place. How’s your routing and authentication set up? If your View gets instantiated before the redirect, so will your masterpage, which could provoke this behaviour.

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

Sidebar

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.