簡體   English   中英

使用Java重定向從ASP.NET與本地文件不同?

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

如果雙擊該文件,則本地磁盤上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>

我試圖將其設置為在Page_load上推送的asp.net頁面,但它似乎無法正常工作。 參見下面的代碼:

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

它不能使工作安靜。它會重定向並發布/傳遞值。但是不能完全登錄嗎?

我錯過了什么嗎?

謝謝

更新:上面的代碼似乎正常工作。 (即,隱藏字段已加載),表單onload會自動重定向到網站等。

看來以下情況使它無法正常工作:

本地文件中的相同HTML / Javascript =工作(注意...引用者為空白),但是與IIS相同=失敗(我可以看到的唯一區別是引用者是mywebsite,而不是www.skwirk.com或BLANK)。

我相信我可以通過以下方法解決此問題:

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事件並添加一個Submit按鈕並手動登錄時,它會記錄日志嗎?
  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功能的第二個標簽將不會觸發。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM