I would like to set a session variable in code behind so after receiving an ajax call result based on the result of that set a session variable.
This application is an old web form and is not MVC Here is what I did
in my standalone JS ( Tried to post to the same aspx page my value which is true
$(document).ready(function () {
console.log("Document is ready.");
$.ajax({
type: "POST",
url: "CheckBrowser.aspx/SetSessionVariable",
data: JSON.stringify({ value: 'true' }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response)
{
// Handle the server's response (if needed)
console.log("success");
},
error: function (error) {
console.log("AJAX Error: " + error);
}
});
}
The test.aspx has this JS And in test.aspx.cs I defined the function so I could assign the true that i sent during post by Ajax to my session variable using the below method
[WebMethod]
protected void SetSessionVariable(string data)
{
Session["myTest"] = data;
}
However I Get the following error Unknown web method SetSessionVariable [ArgumentException: Unknown web method SetSessionVariable. Parameter name: methodName] System.Web.Script.Services.WebServiceData.GetMethodData(String methodName) +626166 System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs) +218 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +144 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +73'
Any suggestion would be much appreciated
static, and it passes the name of the of the parameter and not just the value.