首页 > 解决方案 > 自动登录到 ASP.Net Web 表单站点

问题描述

我正在尝试构建一个脚本/html 页面来自动登录到我的 ASP.net 站点。批处理脚本就像一个魅力:

@if (@CodeSection == @Batch) @then

@echo off

rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
START iexplore "https://servername/aspx/login.aspx" 
rem the script only works if the application in question is the active window. Set a 
timer to wait for it to load!
timeout /t 2
rem use the tab key to move the cursor to the login and password inputs. Most htmls 
interact nicely with the tab key being pressed to access quick links.
rem %SendKeys% "{TAB}"
rem now you can have it send the actual username/password to input box
%SendKeys% "username"
%SendKeys% "{TAB}"
%SendKeys% "password"
%SendKeys% "{ENTER}"

goto :EOF

@end
// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
share

现在的问题是我在用户名中进行了验证,其中网站最多只接受 12 个字符。当我使用上述脚本时,如果用户名字符大于 12,网站会向用户抛出警告消息。

但是当我的安全团队在我的 asp.net webform 网站上执行网络扫描时,他们能够输入超过 12 个字符,包括许多特殊字符。这是一个有效的安全风险。显然这是我的错,我必须在我的 aspx.cs 页面中执行验证,我会这样做。

我试图通过构建将直接调用我的 aspx.cs 登录方法的 javascript 或 html 代码来复制我的开发人员中的场景。如果这将是 MVC 站点,我会使用下面的代码来实现它。请建议是否有人成功为aspx页面构建脚本或html表单,它将直接登录用户

<asp:TextBox ID="tbUsername" runat="server" TabIndex="1"  MaxLength="12" />

自动登录的 MVC 代码:

<SCRIPT LANGUAGE= "JavaScript">

function GoToStats() {
document.statsform.submit();
}

</SCRIPT>

<body>

<form name= "statsform" action= "https://servername/aspx/Login.aspx" method= 
"post">
<input type= "hidden" name= "shortcutLink" value= "autologin" id= "shortcutLink">
<input type= "hidden" name= "txtUser" id= "UserName" value= "username">
<input type= "hidden" name= "txtPass" id= "Password" value= "password">
</form>

<p><a href= "JavaScript:GoToStats()"> See Your Stats</a></p>

标签: javascriptc#asp.netlogin-script

解决方案


推荐阅读