-
-
Save tomadj/7ed5642f65f9329c5ff5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(document).ready(function () { | |
$("#btnLogUser").click(function () { | |
$.ajax({ | |
type: "POST", | |
url: 'api/test/', | |
error: function (msg) { | |
alert("Error !: " + msg); | |
}, | |
success: function (data) { | |
console.log(data); | |
} | |
}); | |
}); | |
$("#AuthrizeAction").click(function () { | |
$.ajax({ | |
type: "GET", | |
url: 'api/test/', | |
error: function (msg) { | |
alert("Error !: " + msg); | |
}, | |
success: function (data) { | |
console.log(data); | |
} | |
}); | |
}); | |
}); | |
</script> | |
<button id="AuthrizeAction">is Authorize ?</button> | |
<button id="btnLogUser">log</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// POST api/test | |
//Action log user | |
public object Post() | |
{ | |
var success = Membership.ValidateUser("tomadj", "thomas"); | |
if (success) | |
{ | |
FormsAuthentication.SetAuthCookie("tomadj", true); | |
return new { success = true, redirect = "" }; | |
} | |
else | |
{ | |
return new { success = false, redirect = "" }; | |
} | |
} | |
// GET api/test | |
//Authorize action | |
[Authorize] | |
public IEnumerable<string> Get() | |
{ | |
return new string[] { "value1", "value2" }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment