hi,
i ve tried to auto login into an asp.net website. using javascript i can automatically log in to the www.irctc.co.in website but the same code have not worked for the website i ve tried. it have not even fill the username and password in the required filed. it just taken me to the login page of that website. the code i ve used is

<html>
<head>

<script type="text/javascript">

function autoLogin() {
document.webservices.submit();
} 
</script>

</head>

<a href="javascript:autoLogin()">Log me automatically in</a>

<BODY>
<form name="webservices" method=post action="https://www.irctc.co.in/cgi-bin/bv60.dll/irctc/services/login.do" target="new_window" onSubmit="window.open('', 'new_window', 'width=450,height=300,status=yes,resizable=yes,scrollbars=yes)"> 
<input type=hidden id=UserName name="userName" value="xxxxxx"></input> 
<input type=hidden id=Password name="password" value="yyyyyy"></input> 
</form>

</body>
</html>

i dont know where i am wrong. ps correct me.

Dani AI

Generated

your JavaScript form post is a cross-site POST. That pattern is treated as a CSRF attempt by many sites. Modern login flows expect a session cookie issued by an initial GET, plus dynamic hidden fields (e.g., anti-CSRF token, VIEWSTATE/EVENTVALIDATION on ASP.NET apps). If those values or the session cookie are missing or mismatched, the server ignores the credentials and redirects to the login page. That is why your fields appear not to fill and you land back on the login screen.

A reliable approach is server-side, keeping cookies and tokens across requests. Building on what is doing, here is a minimal C# HttpClient workflow that fetches the login page, extracts a token, then posts credentials and follows redirects. Adjust URLs and field names to match the target site (inspect with your browser’s Network tab).

var handler = new HttpClientHandler {
    CookieContainer = new CookieContainer(),
    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
    AllowAutoRedirect = false
};
using var client = new HttpClient(handler) { BaseAddress = new Uri("https://target.example") };
client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0");

var loginGet = await client.GetAsync("/login");
var html = await loginGet.Content.ReadAsStringAsync();
var token = Regex.Match(html, "name=\"(__RequestVerificationToken|csrf)\" value=\"([^\"]+)\"")
                 .Groups[2].Value;

var form = new FormUrlEncodedContent(new[] {
    new KeyValuePair<string,string>("userName","XXXX"),
    new KeyValuePair<string,string>("password","YYYY"),
    new KeyValuePair<string,string>("__RequestVerificationToken", token)
});
var post = await client.PostAsync("/services/login.do", form);
if (post.StatusCode == HttpStatusCode.Found && post.Headers.Location != null)
    await client.GetAsync(post.Headers.Location); // now authenticated

Tips:

  • Use DevTools: perform a real login, compare every posted field and header, and replicate them.
  • Keep the same CookieContainer for GET and POST.
  • Check success by looking for an auth-only element or a specific auth cookie.
  • Respect the site’s terms; many services add CAPTCHA or rate limits to block automation.
  • for Yammer, do not scrape logins; use OAuth with their official API.

hello guys,


actually i ve got this url when i made google search for "autologin into asp.net website". i can understand the concept they ve explained. but i dont know which language they have mentioned [whether it is c# or asp.net]. and how to implement that code.
so anybody pls go through the link below.

it would be very helpful for my project if u go through it and explain me how and where to implement it.
expecting fast replies guys since im in urge to complete my project soon. pls..

Thanks in advance.

hey i really wondered that no body ve the knowledge in this stream to help me! y cant u help me regarding this since i need this for my project..


come on guys .... make ur reply soon..

protected void Button1_Click(object sender, EventArgs e)
    {
        CookieContainer cookies = LoginIrctc();
        //ClickFlickrButton(cookies, TextBox1.Text);  
    }
    private CookieContainer LoginIrctc()
    {
        string appURL = "https://www.irctc.co.in/cgi-bin/bv60.dll/irctc/services/login.do";
        string strPostData = String.Format("userName={0}&password={1}",
        "XXXX", "YYYY");

        // Setup the http request.      
        HttpWebRequest wrWebRequest = WebRequest.Create(appURL) as
        HttpWebRequest;
        wrWebRequest.Method = "post";
        wrWebRequest.ContentLength = strPostData.Length;
        wrWebRequest.ContentType = "application/x-www-form-urlencoded";
        CookieContainer cookieContainer = new CookieContainer();
        wrWebRequest.CookieContainer = cookieContainer;

        // Post to the login form.      
        StreamWriter swRequestWriter = new
        StreamWriter(wrWebRequest.GetRequestStream());
        swRequestWriter.Write(strPostData);
        swRequestWriter.Close();

        // Get the response.      
        HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();

        // Read the response      
        StreamReader srResponseReader = new
        StreamReader(hwrWebResponse.GetResponseStream());
        string strResponseData = srResponseReader.ReadToEnd();
        srResponseReader.Close();

        //YOU ARE NOW LOGGED IN TO IRCTC!      
        Response.Write(strResponseData);      
        return cookieContainer;
    }











<form id="form1" runat="server">
    <div>
    
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
        
    
    </div>
    </form>

we also looking same thing.

commented: No! You have to start a thread to put your problem. -3

I want same method implementation for yammer account? Any solution appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.