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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:48:26+00:00 2026-05-21T02:48:26+00:00

I have a asp mvc application consuming wcf rest services (all on the same

  • 0

I have a asp mvc application consuming wcf rest services (all on the same box). For authentication calls,
I am trying to set cookies inside a wcf rest service.

Code on the client side –

        HttpResponseMessage resp;
        HttpClient client = new HttpClient("http://localhost/auth/login/");
        resp = client.Get();

In the webservice I just use FormsAuthentication to set an authcookie.

        HttpCookie authCookie = FormsAuthentication.GetAuthCookie("foo", false);
        HttpContext.Current.Response.Cookies.Add(authCookie);

Assuming the credentials are hardcoded in the code – If I physically navigate to the browserpage

       http://localhost/auth/login 

(hard code credentials in the code) I can see that the authentication cookie is being set. However, if I just invoke it through code (as shown above) the authentication cookie is not being set.

Is there something obvious that I am overlooking here?

  • 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-21T02:48:27+00:00Added an answer on May 21, 2026 at 2:48 am

    When you call the WCF service programatically the cookie it sets is stored in the HttpClient instance. The client browser never sees it so it is never set inside it. So you will need to set it manually:

    using (var client = new HttpClient("http://localhost/auth/login/"))
    {
        var resp = client.Get();
        // Once you get the response from the remote service loop
        // through all the cookies and append them to the response
        // so that they are stored within the client browser.
        // In this collection you will get all Set-Cookie headers
        // sent by the service, so find the one you need and set it:
        foreach (var cookie in result.Headers.SetCookie)
        {
            // the name of the cookie must match the name of the authentication
            // cookie as you set it in your web.config.
            var data = cookie["SomeCookieName"];
            Response.AppendCookie(new HttpCookie("SomeCookieName", data));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ASP MVC 3 application. I created WCF REST JSON Service and added
I have an ASP.NET MVC application, with some RESTful services that I'm trying to
I have an ASP.Net MVC application and I'm using Forms authentication in SQL Server.
I have asp.net mvc 2 application. since couple of days I was trying to
I have an asp.net mvc application and i am trying to assign value to
I have an asp.net MVC application that calls another service to generate a pdf.
I have ASP.NET MVC application, where I keep all of drop down values in
I have an Asp.Net MVC application using Forms Authentication that is published to the
I have an ASP.NET MVC application. I am having multiple drop-down list in my
I have an ASP.NET MVC application that uses Fluent NHibernate and AutoMapper. I am

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.