I am currently facing an issue in my ASP.NET C# project where I need to execute a Json by clicking on a tag, but this action ends the session. To resolve this, I have to call the method RestartSesion().
The code for this is located in the MasterPage. However, when I try to click on the tag, I only receive an alert with the text "Error."
Let me explain what I have done so far. I have a class named VSesion with multiple methods, and the one I am focusing on right now is RestartSesion.
public static void ReiniciarSesion()
{
HttpContext.Current.Session.Abandon();
HttpContext.Current.Response.Redirect(Resources.SitePages.Login);
}
The method ReiniciarSession is called in Template.Master.
[WebMethod]
public static void ReiniciarSession()
{
VSesion.ReiniciarSesion();
}
However, the trouble arises in Template.Master. Here is the related script:
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$("#Reiniciar").click("click", function() {
ReiniciarSession();
});
});
function ReiniciarSession() {
$.ajax({
type: "POST",
url: "Template.Master/ReiniciarSession",
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus + ": " + XMLHttpRequest.responseText);
}
});
}
</script>
Below is the HTML template:
<ul>
<li>
<a href="#" id="Reiniciar">
<span>Salir</span>
</a>
</li>
</ul>
<script src="JS/jquery.js" type="text/javascript"></script>
<script src="JS/jquery-1.11.3.min.js" type="text/javascript"></script>
I would greatly appreciate any assistance or insights on this issue. Thank you!.