You create a Microsoft ASP.NET application by using the Microsoft .NET Framework version 3.5.
You create a login Web form by using the following code fragment.
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:TextBox runat="server" ID="txtUser" Width="200px" />
<asp:TextBox runat="server" ID="txtPassword" Width="200px" />
<asp:Button runat="server" ID="btnLogin" Text="Login" OnClientClick="login(); return false;" />
When a user clicks the btnLogin Button control, the login() client-side script is called to authenticate the user. The credentials provided in the TextBox controls are used to call the client-side script.
You also add the following client-script code fragment in the Web form. (Line numbers are included for reference only.)
01 <script type="text/javascript">
02 function login() {
03 var username = $get(‘txtUser’).value;
04 var password = $get(‘txtPassword’).value;
05
06 // authentication logic.
07 }
08 function onLoginCompleted(validCredentials, userContext,
09 methodName)
10 {
11 // notify user on authentication result.
12 }
13
14 function onLoginFailed(error, userContext, methodName)
15 {
16 // notify user on authentication exception.
17 }
18 </script>
The ASP.NET application is configured to use Forms Authentication. The ASP.NET AJAX authentication service is activated in the Web.config file.
You need to ensure that the following workflow is maintained:
On successful authentication, the onLoginCompleted clien-script function is called to notify the user.
On failure of authentication, the onLoginFailed clien-script function is called to display an error message.
Which code segment should you insert at line 06?
A.
var auth = Sys.Services.AuthenticationService;
auth.login(username, password, false, null, null,onLoginCompleted, onLoginFailed, null);
B.
var auth = Sys.Services.AuthenticationService;
auth.set_defaultFailedCallback(onLoginFailed);
var validCredentials = auth.login(username, password, false, null, null, null, null, null);
if (validCredentials)
onLoginCompleted(true, null, null);
else onLoginCompleted(false, null, null);
C.
var auth = Sys.Services.AuthenticationService;
auth.set_defaultLoginCompletedCallback(onLoginCompleted);
try {
auth.login(username, password, false, null, null, null, null, null);
} catch (err) {
onLoginFailed(err, null, null);
}
D.
var auth = Sys.Services.AuthenticationService;
try {
var validCredentials = auth.login(username, password, false, null, null, null, null, null);
if (validCredentials) onLoginCompleted(true, null, null);
else onLoginCompleted(false, null, null);
} catch (err) {
onLoginFailed(err, null, null);
}
Explanation:
Sys.Services.AuthenticationService.login(userName, password, isPersistent, customInfo, redirectUrl, loginCompletedCallback, failedCallback, userContext);userName
(required) The user name to authenticate.
password
The user’s password. The default is null.
isPersistent
true if the issued authentication ticket should be persistent across browser sessions; otherwise, false. The default is false.
redirectUrl
The URL to redirect the browser to on successful authentication. If null, no redirect occurs. The default is null.
customInfo
Reserved for future use. The default is null.
loginCompletedCallback
The function to call when the login has finished successfully. The default is null.
failedCallback
The function to call if the login fails. The default is null.
userContext
User context information that you are passing to the callback functions.