2012年4月29日 星期日

如何在ASP.NET Web Services 中使用 Session


Step 1. 先行設定web.config檔,加入以下這段Code
<system.web>
.....
<!--主要是以下這行,可參考:http://msdn.microsoft.com/zh-tw/library/h6bb9cz9(v=vs.80).aspx-->
  <sessionState mode="InProc" />
.....
</system.web>

Step 2.設定完web.config檔後,接著必須在asmx檔中作設定,如下...
    '在WebMethod括號內加上EnableSession:=True即可
    <System.Web.Services.WebMethod(EnableSession:=True)> _
    <System.Web.Script.Services.ScriptMethod()> _
    Public Function GetServerTime(ByVal format As String) As String
        ....
        Session("time_data")=Now.ToString(format)
        ....
    End Function


詳細說明可參考:http://www.iiiedu.org.tw/knowledge/knowledge20030630_2.htm

沒有留言:

張貼留言