Skip to content

Instantly share code, notes, and snippets.

@tomadj
Created April 29, 2013 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomadj/7ed5642f65f9329c5ff5 to your computer and use it in GitHub Desktop.
Save tomadj/7ed5642f65f9329c5ff5 to your computer and use it in GitHub Desktop.
<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>
// 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