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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:57:59+00:00 2026-06-17T12:57:59+00:00

I have a Windows application which needs to call a Forms Authenticated MVC action.

  • 0

I have a Windows application which needs to call a Forms Authenticated MVC action. The problem is, I am not sure how to authenticate a call from a Windows application into a Forms Authenticated MVC application.

The following code returns the login page. Is there a way to allow the below code to work with Forms Authentication by whatever means, or do I need to create a new Web API project which uses Basic Authentication for this to work?

WebRequest req = WebRequest.Create("http://myurl/protectaction");
req.Credentials = new NetworkCredential("username", "password");

var res = req.GetResponse();

Thank you very much for your help,

Richard Hughes

  • 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-17T12:58:00+00:00Added an answer on June 17, 2026 at 12:58 pm

    You could use a CookieContainer to store the FormsAuthentication cookie that is emitted by the LogOn action. So basically you will send a first request to the LogOn action and then reuse the same WebRequest instance for subsequent requests.

    This way you will be sending your credentials over the wire only once.

    For example:

    var container = new CookieContainer();
    
    var req = (HttpWebRequest)WebRequest.Create("http://myurl/account/logon");
    req.CookieContainer = container;
    req.Method = "POST";
    using (var writer = new StreamWriter(req.GetRequestStream()))
    {
        var data = HttpUtility.ParseQueryString(string.Empty);
        data["username"] = "john";
        data["password"] = "secret";
        writer.Write(data.ToString());
    }
    using (var res = req.GetResponse())
    {
        // You could check here if login was successful
    }
    
    req = (HttpWebRequest)WebRequest.Create("http://myurl/protectedresource");
    req.CookieContainer = container;
    using (var res = req.GetResponse())
    using (var reader = new StreamReader(res.GetResponseStream()))
    {
        string result = reader.ReadToEnd();
        // do something with the protected resource
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows form application which needs to be the TopMost. I've set
Our C# (V3.5) application needs to call another C++ executable which is from another
I have a Windows application which has a browser in it. The Windows application
I have a Windows Service application which uses a Threading.Timer and a TimerCallback to
I have a C# windows application which does the following: 1) the main form
I have a windows service application which works using remoting. It is used to
i have a windows application made in VB.NET which maintains a database, and i
I have two windows application, one is a windows service which create EventWaitHandle and
Hai every one I am developing an windows application in which i have to
i have an windows mobile application written in c# compact framework which use barcode

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.