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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:12:38+00:00 2026-05-31T08:12:38+00:00

I have a controller / action in an ASP.NET MVC3 app. It handles the

  • 0

I have a controller / action in an ASP.NET MVC3 app. It handles the post request for a user login. I am trying to simulate that but from a desktop winForms app.

My controller looks like this:

  [HttpPost]
  [AllowAnonymous]
  public virtual ActionResult LogOn(LogOnModel model, string returnUrl)
  {
    //authenticate user logic
  }

I’m generating my HTTP request this way:

public static bool AuthenticateClient(Client client, string username, string password)
{
// change these field names to whatever elements your login page is expecting
string usernameField = username;
string passwordField = password;

        string loginUrl = "http://localhost/Account/LogOn/";

        // format login request
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(loginUrl);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.AllowAutoRedirect = false;
        request.CookieContainer = new CookieContainer();

        // format and send login data
        string requestData = JSON.Serialize(new LogOnModel(usernameField, passwordField, false));

        StreamWriter sw = new StreamWriter(request.GetRequestStream());
        sw.Write(requestData);
        sw.Close();

        // get the login response
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        StreamReader sr = new StreamReader(response.GetResponseStream());
        string responseData = sr.ReadToEnd();
        sr.Close();

        // retrieve the session ID
        string sessionId = null;
        foreach (Cookie cookie in response.Cookies)
        {
            if (cookie.Name == AuthCookieName)
            {
                sessionId = cookie.Value;
            }
        }

        // could not authenticate
        if (sessionId == null)
        {
            return false;
        }

        // send the session ID with every request
        client.OnRequestCreated = (args) =>
        {
            args.Request.Headers["Cookie"] = string.Format("{0}={1}", AuthCookieName, sessionId);
        };
        return true;
    }

Typically, I can make Ajax requests from jQuery and pass it the same object parameters that the Controller Action is expecting (the LogonModel in this case), however, when I do that from my desktop app, it’s showing up as null for me each time in the action.

So my question is, how can I make the request from my desktop winforms app, and fill the object (LogonModel) in the controller so that I can authenticate?

  • 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-31T08:12:40+00:00Added an answer on May 31, 2026 at 8:12 am

    (For completeness…)

    You can never be too sure whether you are framing the request right. Personally I’ve found it easier to monitor and compare the calls using Fiddler then refine and emulate as necessary…

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

Sidebar

Related Questions

If I have an ASP.NET MVC controller action that is called from a jQuery
I am trying to send some JSON data to my ASP.NET MVC3 controller action
i have an asp.net mvc site and i have a controller action that emails
I have a very simple asp.net mvc3 app that uses jquery::getJSON to call into
On ASP.NET MVC 3, assume that we have following controller action: public ActionResult Index()
I have an asp.net mvc application with a route similar to: routes.MapRoute(Blog, {controller}/{action}/{year}/{month}/{day}/{friendlyName}, new
ASP.Net MVC Controllers have several methods of forwarding control to another controller or action.
I have an ASP.Net MVC Controller with a 'MapColumns' action along with a corresponding
I have a controller action that checks this.User.Identity.IsAuthenticated What do you suggest how to
With ASP.NET MVC3 (Razor) I have a simple page that loads a jQuery UI

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.