I am trying to call a WebMethod using AJAX in ASP.net
When debugging, I encountered the following error
{Message: "Authentication failed.", StackTrace: null,…}
ExceptionType: "System.InvalidOperationException"
Message: "Authentication failed."
StackTrace: null
AJAX:
<script type="text/javascript">
function SaveRecord() {
//Get control's values
var year = $("#yeartxt").val();
var title = $("#titletxt").val();
var content = $("#contenttxt").val();
//Jquery Ajax call to server side method
$.ajax({
type: "POST",
url: "Page.aspx/InsertDetails",
data: "{'Year':" + year + ",'Title':" + title + ",'Content':" + content + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert("Updated!");
}
});
}
</script>
WebMethod:
[WebMethod]
public static string InsertDetails(string Year, string Title, string Content)
RouteConfig:
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings);
WebConfig:
<authentication mode="Forms">
<forms loginUrl="./SignIn.aspx"></forms>
</authentication>
I implemented the form authentication using ASP.net Identity.
Any ways to solve this?
2
Answers
It is probably your data object which is not well defined.
abd then in your request:
THis should work, as you have mentioned the data type to be json
Try this code
RouteConfig:
Comment this code