I am building a calendar with a reminder popup in ASP.NET WebForms. I want to fetch events from a SQL Server database and display them when a user clicks a date.
Currently, I tried using a Shared WebMethod with EnablePageMethods="true" like this:
_
Public Shared Function GetEvents(dateStr As String) As String
' SQL fetch logic
End Function
And call it via jQuery AJAX:
$.ajax({
type: "POST",
url: "Cal.aspx/GetEvents",
data: JSON.stringify({ dateStr: dateStr }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) { ... }
});
Problems I face:
When calling the WebMethod, I get a 401 Unauthorized error.
Using
EnablePageMethodsandShared WebMethodseems tricky with authentication.
What I want:
Fetch events from the database and show them in a popup for a selected date.
Avoid 401 errors and make it simple to work with jQuery/AJAX.
What I’ve tried:
Enabling
EnablePageMethods="true"Using
SharedWebMethodsAttempting anonymous access in IIS
Question:
What is the best way to fetch and display data in a calendar popup in WebForms