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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:37:03+00:00 2026-05-11T20:37:03+00:00

I am using the UserData Property of the FormsAuthenticationTicket to store some userspecific information.

  • 0

I am using the UserData Property of the FormsAuthenticationTicket to store some userspecific information. I have a HelperClass which deserializes this UserData into a custom Object for strongly-typed access. I have my controller setup as follows

public class SomeController : Controller
{
    private CookieData _cookieData;

    public SomeController()
    {
        _service = new ForderungsStellerService(new ModelStateWrapper(this.ModelState));
        HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
        _cookieData= GetSessionData.FromCookie(ticket);
    }
}

The problem seems to be, that Request is null at controller construction time. When accessing Request.Cookies from an ActionMethod, this snippet is working.

I would like to have the _cookieData object be filled within the constructor for DRY reasons.

Does anyone has a hint on that problem?

best regards…

  • 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-11T20:37:04+00:00Added an answer on May 11, 2026 at 8:37 pm

    I would create a ModelBinder that understands CookieData and how to get it out of the Request object. I fear the unit-test creation code necessary to make the constructor happy. If you take it as a parameter to the controller with a Model Binder you can avoid that test overhead.

    public class SomeController : Controller
    {
      // only need to pass in the data object for unit testing.
      // ModelBinder takes care of DRY
      public ActionResult Index(CookieData cookieData)
      {
      }
    }
    

    The answer to why it doesn’t work in the constructor is that the Controller hasn’t been initialized with the ControllerContext at that point.

    public HttpContextBase HttpContext {
      get {
        return ControllerContext == null 
          ? null 
          : ControllerContext.HttpContext;
      }
    }
    

    If you really want to do it in the constructor (don’t) then use HttpContext.Request instead of the wrapper. But by doing so you will have made your code untestable and your alignment will drop by 3 points.

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

Sidebar

Ask A Question

Stats

  • Questions 202k
  • Answers 202k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Hey! Have you looked at htis document/examples: Django Validation Maybe… May 12, 2026 at 8:20 pm
  • Editorial Team
    Editorial Team added an answer DocBook to Wiki might be useful, though it converts from… May 12, 2026 at 8:20 pm
  • Editorial Team
    Editorial Team added an answer Apache Commons IO comes to the rescue (again). The Commons… May 12, 2026 at 8:20 pm

Related Questions

I'm using Linq2SQL and I'm pretty new to it. I've got a User table
I'm using SQL Server 2005 with Reporting Services. I have many reports installed, some
Bug: I've got an ASP.NET web application that occasionally sets identical cookie keys for
Is there a good way to assign ViewData to nested master pages? For example,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.