简体   繁体   English

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

[英]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.. 如果双击该文件,则本地磁盘上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>

I tried to make this an asp.net page being pushed on Page_load, but it doesn't appear to work correctly. 我试图将其设置为在Page_load上推送的asp.net页面,但它似乎无法正常工作。 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... (即,隐藏字段已加载),表单onload会自动重定向到网站等。

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). 本地文件中的相同HTML / Javascript =工作(注意...引用者为空白),但是与IIS相同=失败(我可以看到的唯一区别是引用者是mywebsite,而不是www.skwirk.com或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 ? 当您删除onLoad事件并添加一个Submit按钮并手动登录时,它会记录日志吗?
  2. You could use onload='document.forms[0].submit(); 您可以使用onload='document.forms[0].submit(); instead of using the form's name as you ionly got one form element after all 而不是使用表单名称,因为您毕竟只有一个表单元素

d. 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. 我可能会丢失一些东西,但是对我来说,最明显的是您有重复的body标签。 Therefore, the second tag with the onload function won't fire. 因此,带有onload功能的第二个标签将不会触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用javascript函数从asp.net页面重定向到另一个页面 - Redirect from asp.net page to another using javascript function 使用 javascript 重定向 Asp.net MVC - Using javascript to redirect Asp.net MVC 使用浏览器的ASP.NET下载文件并同时重定向到另一个页面 - ASP.NET download file using browser and redirect to another page at the same time Javascript无法使用Ajax ASP.Net进行response.redirect - Javascript not working on response.redirect using ajax ASP.Net 如何使用 Z686155AF75A60A0EDD3F6E9D80C1 从 ASP.NET Controller 重定向到另一个 web 页面? - How do I redirect to another web page from an ASP.NET Controller using JavaScript? 从ASP.NET文本框中使用JavaScript - Using javascript from an ASP.NET textbox 是否可以使用Javascript或ASP.NET从本地端口读取数据? - Is it possible to read data from a local port using Javascript or ASP.NET? 将网页重定向到asp.net中的同一选项卡 - Redirect webpage to same tab in asp.net 使用 vanilla javascript ajax [ASP.NET Core] 在同一个 POST 请求中上传文件和 Json 数据 - Upload file and Json data in the same POST request using vanilla javascript ajax [ASP.NET Core] 使用asp.net mvc中的javascript重定向到POST - redirect to POST with javascript in asp.net mvc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM