使用Javascript重定向与ASP不一样.. NET作为本地文件



本地磁盘上的TEXT文件中的以下代码可以很好地用于自动登录skwirk网站如果你双击文件..

<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>

我试图使这是一个asp.net页面被推到Page_load,但它似乎不能正常工作。参见下面的代码:

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();        
        }
    }
}

它不安静的工作…它重定向并发布/传递值。但没有完全登录????

我错过了什么?????

感谢

UPDATE:上面的代码看起来工作正常。(即。隐藏字段被加载),表单onload自动重定向到网站等…

下面的代码会使它停止工作:

相同的HTML/Javascript在本地文件=工作(注意…推荐人为空白)相同,但从IIS = FAIL(唯一的区别,我可以看到如果REFERER是我的网站,而不是www.skwirk.com或空白)。

我相信我可以通过以下操作来解决这个问题:

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

有什么想法吗?

  1. 当你删除onLoad事件并添加提交按钮并手动登录时,它会记录吗?
  2. 你可以使用onload='document.forms[0].submit();而不是使用表单的名称,因为你只有一个表单元素毕竟

d。

尝试重写页面呈现方法

    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>");
    }

我可能错过了一些东西,但对我来说最明显的是你有一个重复的body标签。因此,第二个带有onload函数的标签将不会触发

最新更新