简体   繁体   中英

Redirect using Javascript not the same from ASP.NET as local file?

The following code in a TEXT file on local disk works fine as an autologin for the skwirk website if you double click on the file..

<html>
<title>Skwirk</title>
<body onload='document.forms["Skwirk"].submit()'>
<form name="Skwirk" action="http://www.skwirk.com/homepageV2/login_process.asp"
      method="POST">
<input type="hidden" name="query_string" value="">
<input type="hidden" name="username"     value="usernamegoeshere">
<input type="hidden" name="password"     value="mypasswordhere">
<input type="hidden" name="login_submitbutton.x" value="29">
<input type="hidden" name="login_submitbutton.y" value="10">
</form>
</body>
</html>

I tried to make this an asp.net page being pushed on Page_load, but it doesn't appear to work correctly. See code below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace Skwirk
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string Url = "http://www.skwirk.com/homepageV2/login_process.asp";
            string formId = "Skwirk";            
            string stage  = "username";
            string pass   = "password";

            StringBuilder htmlForm = new StringBuilder();
            htmlForm.AppendLine("<html>");
            htmlForm.AppendLine("<title>Skwirk</title>");
            htmlForm.AppendLine("<body>");

            htmlForm.AppendLine(String.Format("<body onload='document.forms[\"{0}\"].submit()'>", formId));
            htmlForm.AppendLine(String.Format("<form name='{0}' method='POST' action='{1}'>", formId, Url));
            htmlForm.AppendLine(string.Format("<input type='hidden' name='username'     value='{0}'>",stage ));
            htmlForm.AppendLine(string.Format("<input type='hidden' name='password'     value='{0}'>",pass  ));
            htmlForm.AppendLine("<input type='hidden' name='login_submitbutton' value=''>");
            htmlForm.AppendLine("</form>");
            htmlForm.AppendLine("</body>");
            htmlForm.AppendLine("</html>");

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(htmlForm.ToString());
            HttpContext.Current.Response.End();        
        }
    }
}

It doesn't quiet work.. It redirect and posts/passes the values.. But isn't fully logged in ????

Have I missed something ?????

Thanks

UPDATE: The above code appears to work correctly. (ie. Hidden fields are loaded), the form onload automatically redirects to the website etc...

It would appear that the following is stoppping it working:

Same HTML/Javascript in a local file = WORKING (Note... REFERER is BLANK) Same but from IIS = FAIL (The only difference I can see if REFERER is mywebsite, not www.skwirk.com or BLANK).

I believe I could fix it by doing the following:

Override what IIS/ASP.NET sends as the REFERER string.. Either Force it to be BLANK
or force it to be www.skwirk.com

Any ideas ?

  1. Does it log when you remove the onLoad event and add a submit button and do the login manually ?
  2. You could use onload='document.forms[0].submit(); instead of using the form's name as you ionly got one form element after all

d.

Try to override page render method

    protected override void Render(HtmlTextWriter writer)
    {

        string Url = "http://www.skwirk.com/homepageV2/login_process.asp";
        string formId = "Skwirk";
        string stage = "username";
        string pass = "password";

        StringBuilder htmlForm = new StringBuilder();
        writer.WriteLine("<html>");
        writer.WriteLine("<title>Skwirk</title>");
        writer.WriteLine("<body>");

        writer.WriteLine(String.Format("<body onload='document.forms[\"{0}\"].submit()'>", formId));
        writer.WriteLine(String.Format("<form name='{0}' method='POST' action='{1}'>", formId, Url));
        writer.WriteLine(string.Format("<input type='hidden' name='username'     value='{0}'>", stage));
        writer.WriteLine(string.Format("<input type='hidden' name='password'     value='{0}'>", pass));
        writer.WriteLine("<input type='hidden' name='login_submitbutton' value=''>");
        writer.WriteLine("</form>");
        writer.WriteLine("</body>");
        writer.WriteLine("</html>");
    }

I could be missing something, but the most obvious thing to me is that you have a duplicate body tag. Therefore, the second tag with the onload function won't fire.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM