Ajax login with ASP.Net MVC 2

This question is related to ASP.NET forms authentication without redirection , I cannot get it to work. MVC 2 changed its script files, and now they got it, as indicated here:

http://www.asp.net/ajaxlibrary/CDNAjax4.ashx

Now I just shoot in the dark, but the trial version and the error narrowed me down to power on

MicrosoftAjax.js
MicrosoftAjaxCore.js
MicrosoftAjaxComponentModel.js
MicrosoftAjaxSerialization.js
MicrosoftAjaxNetwork.js
MicrosoftAjaxWebServices.js
MicrosoftAjaxApplicationServices.debug.js

The problem is that I get a javascript exception:

Microsoft JScript runtime error: Sys.InvalidOperationException: The web service path was not installed.

From googling around, I found that this path should be "~ / ScriptServices_AuthenticationService.asmx", but something like:

Sys.Services._AuthenticationService.DefaultWebServicePath = "~/ScriptServices_AuthenticationService.asmx";

not working (I assume this is a private member). So the question is, does anyone know how to make ajax / async FormsAuth work? Is there a definitive guide on which js file depends on the various MS ajax services? Finally, if none of the above is there, there is a way to make FormsAuth on the server side so that it does not redirect (so I can just call the controller action with the ajax form)? ... I tried using FormsAuthentication.SetAuthCookie (), but this did not seem to work for me.

: , FormsAuthentication.SetAuthCookie() , , Response (, , ). , .

: , . ajax . . ajax, , . :

public JsonResult CreateAsync(LoginForm form)
{
    CreateAccount(form);

    FormsAuthentication.RedirectFromLoginPage(form.Email, false);

    return Json(
        new
        {
            Email = form.Email,
            Name = form.Name,
            Message = "Success"
        });
}

, . FormsAuth.SetAuthCookie, , .

+3
3

, . FormsAuthentication.Authenticate() RedirectFromLoginPage.

, JSON.

0

? Html.Form Ajax.Form? Ajax.Form( Ajax.ActionForm), , . , .

, . , , , , . , .

-1

jQuery .

$( "# login_button" ). (() {
$.ajax({URL: "/Controller/CreateAsync", : {E-mail: "someone@somewhere.com", : "asdfasfd" }, : "POST", dataType: "json",
: () {          // - })});

. http://api.jquery.com/jQuery.ajax/

-1

Source: https://habr.com/ru/post/1758785/


All Articles