[英]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 ? 有任何想法吗 ?
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.