如何实现客户端Ajax登录的Asp.Net MVC(链接到解决方案的Asp.Net Web表单是在这里)是在、表单、如何实现、客户端

由网友(尼玛算个蛋@)分享简介:我想实现在Asp.Net MVC客户端AJAX登录。我曾经有过这样设置就好上的WebForms,但现在我已经搬到了MVC它给了我一些麻烦。I'm trying to implement a client-side ajax login on Asp.Net MVC. I used to have this set u...

我想实现在Asp.Net MVC客户端AJAX登录。我曾经有过这样设置就好上的WebForms,但现在我已经搬到了MVC它给了我一些麻烦。

I'm trying to implement a client-side ajax login on Asp.Net MVC. I used to have this set up just fine on WebForms, but now that I've moved to MVC it's giving me some troubles.

如果你想在客户端的Ajax登录Asp.Net Web表单的教程,可以发现here - 简单,A ++

If you'd like a tutorial on Client-side Ajax Login for Asp.Net Webforms, it can be found here -- Easy, A++

现在......由于某种原因,它不工作的Asp.Net MVC。

Now... for some reason it's not working for Asp.Net MVC.

我用的是完全一样的教程作为Web表单,当它执行 ssa.login除了() (等效: Sys.Services.AuthenticationService.login())它没有做任何事情。

I used the exact same tutorial as for the Webforms, except when it executes the ssa.login() (equivalently: Sys.Services.AuthenticationService.login()) it's not doing anything.

我在同时onLoginComplete()函数和onError的()函数的警报。同时我有一个警报ssa.login被调用前,右后...

I have alerts in both the onLoginComplete() function and the onError() function. As well I have an alert before the ssa.login gets called and right after...

function loginHandler() {
    var username = $("#login_UserName").val();
    var password = $("#login_Password").val();
    var isPersistent = $("#login_RememberMe").attr("checked");
    var customInfo = null;
    var redirectUrl = null;
    // Log them in.
    alert("try login");
    ssa.login(username,
                      password,
                      isPersistent,
                      customInfo,
                      redirectUrl,
                      onLoginComplete,
                      onError);
    alert("made it here");
}

第一个警报触发,但第二个没有,这意味着该函数失败。 下面是我从Asp.Net阿贾克斯拉功能,向您展示:

The first alert fires but the second one doesn't which means the function is failing. Here's the function I pulled from Asp.Net Ajax to show you:

function(c, b, a, h, f, d, e, g) {
    this._invoke(this._get_path(), "Login", false, { userName: c, password: b, createPersistentCookie: a }, Function.createDelegate(this, this._onLoginComplete), Function.createDelegate(this, this._onLoginFailed), [c, b, a, h, f, d, e, g]);
}

任何有为什么它没有任何想法?

Anyone have any idea of why it's failing?

推荐答案

正在使这个复杂得多,它需要。所有你需要做的是调用与AJAX调用您的账户/登录方法。你并不需要身份验证服务的复杂性,虽然你可能要检测是否通过AJAX登录并返回JSON,而不是一个视图。

You are making this more complicated than it needs to be. All you need to do is call your Account/Login method with the AJAX call. You don't need the complication of the Authentication service, though you probably want to detect whether you are logging in via AJAX and return JSON rather than a View.

function loginHandler() {
    var username = $("#login_UserName").val();
    var password = $("#login_Password").val();
    var isPersistent = $("#login_RememberMe").attr("checked");
    var customInfo = null;
    var redirectUrl = null;
    // Log them in.
    alert("try login");
    $.ajax( {
       url : '<%= Url.Action( "Login", "Account" ) %>',
       type: 'post',
       dataType: 'json',
       data: { username: username,
               password: password,
               isPersistent: isPersistent,
              },
       success: onLoginComplete,
       error: onError
    });
    alert("made it here");  // this will execute before the callback completes...
}
阅读全文

相关推荐

最新文章