Warum kann WebMethod ohne EnableSessionState auf den Sitzungsstatus zugreifen?

Ich habe eine Methode auf einer Seite, die als markiert ist[WebMethod] das verwendet einige Sitzungsstatus als Teil seiner Operation. Nachdem ich diesen Code geschrieben hatte, hatte ich plötzlich einen Flash-Speicher, den Sie verwenden müssenEnableSessionState Wenn Sie den Sitzungsstatus in a verwenden[WebMethod] (siehe z. B. hier:http://msdn.microsoft.com/en-us/library/byxd99hx.aspx). Aber es scheint gut zu funktionieren. Warum?

Beispielcode dahinter:

protected void Page_Load(object sender, EventArgs args) {
    this.Session["variable"] = "hey there";
}
[System.Web.Services.WebMethod]
public static string GetSessionVariable() {
    return (string)HttpContext.Current.Session["variable"];
}

Beispielkörper-HTML:

<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
    function getSession() {
        $.ajax({
            type: 'POST',
            url: 'Default.aspx/GetSessionVariable',
            data: '{ }',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function (msg) {
                document.getElementById("showSessionVariable").innerHTML = msg.d;
            }
        });
        return false;
    }
</script>
<form id="form1" runat="server">
    <div id="showSessionVariable"></div>
    <button onclick='return getSession()'>Get Session Variable</button>
</form>

Antworten auf die Frage(2)

Ihre Antwort auf die Frage