Restart Session on and json


I hope you can help me with this topic, I am working on a project with c #, the problem is that I need to click on a label to execute a Json and it ends the session.

I explain to you what I did.

I have a VSesion class that has several methods, but the one that concerns me today is RestartSession.

public static void ReiniciarSesion()

In my Template.Master.cs I call the previous method in this way.

public static void ReiniciarSession()

In the Template.Master I call it this way..this is where I have the problem.

<script language="javascript" type="text/javascript">
        $(document).ready(function() {
            $("#Reiniciar").click("click", function() {
        function ReiniciarSession() {
                type: "POST",
                url: "TemplateSae.Master/ReiniciarSession",
                data: {},
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: true,
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(textStatus + ": " + XMLHttpRequest.responseText);

Here the label

      <a href="#" id="Reiniciar">

By the way and I forgot I'm using

<script src="JS/jquery.js" type="text/javascript"></script>
<script src="JS/jquery-1.11.3.min.js" type="text/javascript"></script>

I hope you can help me. Thanks. !!

asked by Herlan Baringay Linares 23.11.2016 в 13:56

1 answer


The error is that when trying to access the HttpContext.Current.Session object, it has a null value.

To make the Session object available in a WebMethod, you must add the attribute [WebMethod(EnableSession = true)]

[WebMethod(EnableSession = true)]
public static void ReiniciarSession()
answered by 13.12.2016 в 18:11