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

The Archive Base Latest Questions

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

I am working on a .NET 2.0 winforms application that calls an ASP.NET 2.0

  • 0

I am working on a .NET 2.0 winforms application that calls an ASP.NET 2.0 website. The website is authenticated using forms authentication. The authentication service is enabled in the web.config, and I have done some experiments to confirm that I can access the service via JSON.

Here is my question: is there any built-in code to consume the System.Web.Extensions web services (authenticationService, profileService, etc.) in a purely .NET environment (not ASP.NET)? I can find examples using Silverlight and the later WCF services, but not anything in a 2.0 environment on both client and server. Adding the authentication service as a web service seems like the logical approach, but I could never get it to work pointing to my development server – I suppose that could be a separate question.

If I have to manage the AJAX request and response at a lower level, it’s certainly doable, but if something were already intended for this purpose it would certainly be easier and less error-prone.

  • 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-24T13:39:18+00:00Added an answer on May 24, 2026 at 1:39 pm

    I never got an answer for this, but eventually figured it out with the help of this tutorial. The short answer was yes, I had to manage the AJAX request/response at a fairly low level. Assuming you have a username and password you need to authenticate with, you first need to get an authentication cookie for it. I used the Json.NET library from Newtonsoft for the JSON serialization and deserialization, but you could use anything.

    Cookie GetFormAuthenticationCookie(string username, string password)
            {
                string uriString = ServerName + AUTH_SERVICE_URL;
                Uri uri = new Uri(uriString);
    
                // Need to cast this to HttpWebRequest to set CookieContainer property
                // With a null CookieContainer property on the request, we'd get an
                // empty HttpWebRequest.Cookies property
                HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
                request.Method = "POST";
                request.ContentType = "application/json; charset=utf-8";
                request.CookieContainer = new CookieContainer(); // needed to get non-empty Cookies collection back in response object
    
                // requestContents needs to look like this:
                // {
                //     username = 'theUserName',
                //     password = 'thePassword',
                //     createPersistentCookie = false
                // }
                string requestContents = GetJsonForLoginRequest(username, password);
    
                byte[] postData = Encoding.UTF8.GetBytes(requestContents);
                request.ContentLength = postData.Length;
                using (Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(postData, 0, postData.Length);
                }
    
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    throw new WebException("Response returned HttpStatusCode " + response.StatusCode);
                }
    
                // For now, assuming response ContentType is "application/json; charset=utf-8"
                object responseJson;
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(responseStream);
                    string responseString = reader.ReadToEnd();
    
                    responseJson = JavaScriptConvert.DeserializeJson(responseString);
                }
    
                if (responseJson is bool)
                {
                    bool authenticated = (bool)responseJson;
                    if (authenticated)
                    {
                        // response was "true"; return the cookie
                        return response.Cookies[".ASPXFORMSAUTH"];
                    }
                    else
                    {
                        // apparently the login failed
                        return null;
                    }
                }
                else
                {
                    return null;
                }
            }
    

    Next, add the cookie to subsequent requests. In my case, that meant adding the cookie to the CookieContainer of the web service proxy I was using.

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

Sidebar

Related Questions

I'm working with a .NET 2.0 WinForms application in C#. I noticed something that
I'm working on a WinForm .Net application with the basic UI that includes toolbar
I'm working on a C# winforms application (VS.NET 2008, .NET 3.5 sp 1). I
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I'm working on a .NET WinForms app that needs to print a FEDEX shipping
I am working on a VB.NET WinForms app that was upgraded by Visual Studio
I am working on a winforms application using LINQ to SQL - and am
I am working on .Net framework. I have created an application that creates a
Context: I'm working with a relatively simple winforms application, written in VB.NET on the
I have inherited a working VB.NET 2.0 web app that has several User Controls

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.