【发布时间】:2011-10-03 21:47:35
【问题描述】:
我有一个如下所示的 VB.NET 函数:
<WebMethod()> _
Public Shared Function AuthenticateUser(ByVal UserInfo As String, ByVal Password As String) As Boolean
Dim UserName As String
'Just in case
AuthenticateUser = False
'Extract the user name from the user info cookie string
UserName = Globals.GetValueFromVBCookie("UserName", UserInfo)
'Now validate the user
If Globals.ValidateActiveDirectoryLogin("Backoffice", UserName, Password) Then
AuthenticateUser = True
End If
End Function
我正在尝试像这样从 javascript 调用它:
function DeleteBatchJS()
{if (confirm("Delete the ENTIRE batch and all of its contents? ALL work will be lost."))
var authenticated = PageMethods.AuthenticateUser(get_cookie("UserInfo"), prompt("Please enter your password"))
if (authenticated == true)
{{var completed = PageMethods.DeleteBatchJSWM(get_cookie("UserInfo"));
window.location = "BatchOperations.aspx";
alert("Batch Deleted.");}}}
它调用函数,但不会返回值。浏览代码时,我的 VB 函数会触发(只要输入正确的密码,它就会返回 true),但 javascript 的“已验证”值仍然是“未定义”。就像您无法将值从 VB 函数返回到 javascript。
我也试过
if PageMethods.AuthenticateUser("UserName", "Password")
{
//Stuff
}
但还是没有运气。
我做错了什么?
谢谢,
杰森
【问题讨论】:
-
旁注,我从不提示输入这样的密码。
-
@Joel -- 密码编码是为了简单起见。真正的代码涉及更多一点
标签: javascript asp.net vb.net pagemethods webmethod