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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:44:52+00:00 2026-06-05T19:44:52+00:00

Setup I am using custom Forms Authentication – all standard stuff. In the Login

  • 0

Setup

I am using custom Forms Authentication – all standard stuff.

In the Login action on my Account controller,

  • I check the user’s details against the db
  • If successful I create a Forms Authentication ticket
  • Store the logged in members db row id in UserData in the ticket
  • Encrypt the ticket
  • Store the ticket in a cookie
  • Add the cookies to the Reponse.Cookies collection
  • Redirect to Index Action on Home Controller

I registered a handler in global asax for the AuthenticateRequest event. In my handler,

  • I retrieve the cookie from HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
  • If the cookie exists I decrypt the value of the Forms Authentication ticket in the cookie
  • Retrieve the user’s details from the db using the Id stored in the authentication ticket UserData.
  • Create a custom principal and set the user (it has a custom LoggedInUser property) to the user I retrieved from the db.
  • Set the HttpContext.Current.User to the custom principal

Problem

I debug a request for the home page after I have logged in and note that the AuthenticateRequest handler in global.asax is hit more than once per page request. I’ve checked the HttpContext.Current.Request.Path and this is because each resource on my page (effectively, every HTTP GET) is firing the authenticate requet, so, GET jquery.js, GET logo.png etc…

Question

On the first handled AuthenticateRequest I go to the db and then set the HttpContext.Current.User to my custom principal. What would be a good way to avoid going to the db for subsequent HTTP GETs that cause the AuthenticatRequest to fire. Effectively, authenticate once and once only until the user closes their browser or until the Authentication Ticket expires.

TIA

  • 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-05T19:44:55+00:00Added an answer on June 5, 2026 at 7:44 pm

    Instead of using the AuthenticateRequest method in your Global.asax I would recommend you writing a global action filter. This way the action filter will apply only before executing some action and populate the User. In fact a custom [Authorize] attribute is the best way to achieve that:

    public class MyAuthorizeAttribute : AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            var authorized = base.AuthorizeCore(httpContext);
            if (!authorized)
            {
                return false;
            }
    
            // TODO: go ahead and work with the UserData from the authentication cookie
            // basically all the steps you described for your AuthenticateRequest handler
            // except for checking the presence of the forms authentication cookie because
            // we know that at this stage it exists and the user was successfully authorized
    
            return true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Rails 3.2.2, I want to setup custom URLs (using State 2 digit :abbr,
I'm using nopCommerce 2.3 and trying to setup a custom Area but the area
I have a custom user registration form at: somepath/register using hook form alter. I
I have a custom workflow that uses the Collect data from a user action,
I have the following setup using Core Data: Nib1: A WindowController with two custom
I'm used to using a standard form with JavaScript validation, custom captcha... etc. Now
I'm using Devise for authentication with two custom fields added = :organization_id and :username
All I have built a windows form application using VS 2005 Standard edition which
I have custom error pages setup using <customErrors mode=On defaultRedirect=~/Home/Error> <error statusCode=404 redirect=~/Home/PageNotFound />
I am trying to set up a custom ASP.NET membership provider to authenticate using

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.