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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:01:25+00:00 2026-06-12T13:01:25+00:00

Final update at the end of this post I am working on it whole

  • 0

Final update at the end of this post

I am working on it whole day, and i cannot make it work:

private void button1_Click(object sender, EventArgs e)
{
    var loginUri = new Uri(@"http://localhost:5898/Account/Login");
    const string strLoginData = "Login=ojejq&Password=ojejqjejq&returnUrl=%2F";

    var cookie = GetAuthCookie(loginUri, strLoginData);
}

public CookieContainer GetAuthCookie(Uri loginUri, string data)
{
    var cookieJar = new CookieContainer();
    var request = (HttpWebRequest)WebRequest.Create(loginUri);
    request.Method = "POST";
    request.CookieContainer = cookieJar;
    request.ContentLength = data.Length;
    request.ContentType = "application/x-www-form-urlencoded";

    var myWriter = new StreamWriter(request.GetRequestStream());
    myWriter.Write(data);
    myWriter.Close();
    request.GetResponse();

    return cookieJar;
}

In my ASP MVC application, I have a /Account/Login POST controller that is not even hit by above code. What am I doing wrong?

Edit: Two login actions in my asp mvc app:

[AllowAnonymous]
public ActionResult Login()
{...}

and

[HttpPost]
[AllowAnonymous]
public ActionResult Login(LoginModel model, string returnUrl)
{...}

Second update: added login model

public class LoginModel
{
    [Required]
    [Display(Name = "Login", ResourceType = typeof(NameResources))]
    [StringLength(16, ErrorMessageResourceName = "LoginLengthError", ErrorMessageResourceType = typeof(NameResources), MinimumLength = 4)]
    public string Login { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Password", ResourceType = typeof(NameResources))]
    [StringLength(32, ErrorMessageResourceName = "PasswordLengthError", ErrorMessageResourceType = typeof(NameResources), MinimumLength = 8)]
    public string Password { get; set; }
}

Third update: I forgot to mention, that in my web.config i have cookieless=”AutoDetect” option set. I don’t know if it makes any changes?

Final update: First of all, thank you guys for your time, everyone who tried to help me gets an upvote. I found out that the problem was not in the code, but in my visual studio dev server. It somehow redirected my button1 POST request, lost data in the process, and changed that request into a GET request. I know, werid, but the code was OK. Thank you for your time.

  • 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-12T13:01:26+00:00Added an answer on June 12, 2026 at 1:01 pm

    I think you should try “UserName” insted of “Login” in:

    const string strLoginData = "UserName=ojejq&Password=ojejqjejq&returnUrl=%2F";
    

    and try this too:

    public CookieCollection GetAuthCookie(Uri loginUri, string data)
    {
        var cookieJar = new CookieContainer();
        var request = (HttpWebRequest)WebRequest.Create(loginUri);
        request.Method = "POST";
        request.CookieContainer = cookieJar;
        request.ContentLength = data.Length;
        request.ContentType = "application/x-www-form-urlencoded";
    
        var myWriter = new StreamWriter(request.GetRequestStream());
        myWriter.Write(data);
        myWriter.Close();
    
        var webResponse = request.GetResponse() as HttpWebResponse;
        return webResponse.Cookies;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

private final List<KeyListener> keyListeners= new CopyOnWriteArrayList<KeyListener>(); public void addKeyListener(KeyListener keyListener){ keyListeners.add(keyListener); } In the
Update: I've added an answer that describes my final solution (hint: the single Expr
I'm working on a project which will post periodic XML updates for users. I'm
I am having the hardest time getting this to properly render and update. What
private static String CONSUMER_KEY = mrnCC41nxtwkdFAmToEhtg; private static final String CONSUMER_SECRET = kmmVuahEspGvdl14aCD1GSBZpeHbxvkpAez7aKaaQ; EditText
Just to be clear, this question is not about how to update a TextView
This exercise was a bit tricky. Figured I'd post my solution to see if
[UPDATE] (when you read my question this is good to know) I had a
this is an update to the previous question that I had about locating peaks
Assuming this class: public class AmIThreadSafe { private int a; private int b; AmIThreadSafe(int

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.