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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:51:01+00:00 2026-06-07T14:51:01+00:00

I have created a module to handle authentication to Microsoft HealthVault. In the BeginRequest

  • 0

I have created a module to handle authentication to Microsoft HealthVault. In the BeginRequest event handler I am checking for the authToken and when it’s received, I am creating a new cookie to hold the user’s information for use later on in the controller.

I am losing the cookie but maybe I am looking in the wrong place.

The event handler take an HttpApplication as the only parameter, so I add the cookie to application.Response.Cookies collection. The question comes down to: is this instance of HttpApplication a singleton? Is it the same as System.Web.HttpContext.Current.ApplicationInstance?

Perhaps though, cookies set at this point in the lifecycle are later wiped out. Is that what I am doing wrong?

Any help is greatly appreciated.

UPDATE

I have changed a few things since I posed the question. I am now handling PreRequestEventHandler in my HttpModule. I am letting HealthVault’s WebApplicationUtilities object do the cookie creation and storage, though conceptually nothing has really changed. I am not having any trouble creating the cookie or reading it the first time after it’s created.

Here is my cookie creation code in the HttpModule event handler:

static void PreRequestHandlerExecute(Object sender, EventArgs e)
{
    HttpContext ctx = System.Web.HttpContext.Current;
        string authToken = ctx.Request.Params["wctoken"];
        if (!String.IsNullOrEmpty(authToken))
        {
            personInfo = WebApplicationUtilities.GetPersonInfo(authToken);
            WebApplicationUtilities.SavePersonInfoToCookie(ctx, personInfo);

            NameValueCollection query = HttpUtility.ParseQueryString(ctx.Request.Url.Query);
            query.Remove("wctoken");
            query.Remove("suggestedtokenttl");

            UriBuilder newUrl = new UriBuilder(ctx.Request.Url);
            newUrl.Query = query.ToString();
            //app.Response.Redirect(newUrl.Uri.OriginalString);
        }
}

Notice that the redirect is commented. On the first request (after auth) the cookie is created and my default action is able to then read it using LoadPersonInfoFromCookie(). I found that doing the redirect caused the cookie not to be sent to the client.

I have also noticed that on the subsequent requests, the cookie is not present in the Request.Cookies collection, so when LoadPersonInfoFromCookie() runs, I end up with a null. Strangely I can see the cookie in the Response object, but the contents are empty.

Here is the action code, just because…

public HttpContext Context
{
    get { return System.Web.HttpContext.Current; }
}

public ActionResult Dashboard()
    {
        try
        {
            HealthVaultAccountModel model = new HealthVaultAccountModel();
            PersonInfo personInfo = WebApplicationUtilities.LoadPersonInfoFromCookie(Context);
            if (personInfo != null)
                model.PersonName = personInfo.Name;
            return View(model);
        }
        catch (Exception ex)
        {
            return RedirectToAction("Index", "Error");
        }
    }

UPDATE

Here is the cookie from the Immediate Window. I even bumped the Expires time out 30 days.

In the default action right after it is created

Context.Request.Cookies["_wcpage"]
{System.Web.HttpCookie}
    Domain: null
    Expires: {8/13/2012 5:24:02 PM}
    HasKeys: true
    HttpOnly: true
    Name: "_wcpage"
    Path: "/"
    Secure: true
    Shareable: false
    Value: "p=1:1234-pVTbctowEP0V..."
    Values: {p=1%3a1234-pVTbctowEP0V...}

In the action on the next request

Context.Request.Cookies["_wcpage"]
null

Interestingly the cookie is defined in the response object, but the value is gone and the expires time is reset.

Context.Response.Cookies["_wcpage"]
{System.Web.HttpCookie}
    Domain: null
    Expires: {1/1/0001 12:00:00 AM}
    HasKeys: false
    HttpOnly: false
    Name: "_wcpage"
    Path: "/"
    Secure: false
    Shareable: false
    Value: ""
    Values: {}
  • 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-07T14:51:03+00:00Added an answer on June 7, 2026 at 2:51 pm

    How are you creating/fetching the cookie? The SavePersonInfoToCookie and LoadPersonInfoFromCookie methods on the WebApplicationUtilities class will do it for you.

    BeginRequest:

    // given an authToken from the querystring/post values
    var personInfo = WebApplicationUtilities.GetPersonInfo(authToken);
    WebApplicationUtilities.SavePersonInfoToCookie(application.Context, personInfo);
    

    Controller:

    var personInfo = WebApplicationUtilities.LoadPersonInfoFromCookie(HttpContext);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a custom module in magento.I have created block class and phtml
i have created a module with this among others this function in it: <?php
I have created a multi module maven project. Now I have shared the project
I am using ASP MVC 2 and Nhibernate. I have created an HTTP Module
I have created a simple Python module and want to distribute it with pip.
I have created a class called Class1, and in another module, I want to
I'm currently developing a module for Drupal 6, in which I have created a
I have a DotNetNuke Module created in DNN 4.9.2. It runs fine on my
I have a module I created for a node.js app. The app also uses
I created a custom module for Orchard following this wonderful guide . I have

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.