原諒我,已經有好幾年了,我的搜索結果好壞參半。在傳統的 .NET 表單應用程式中使用下面的 VB 代碼,ClientKey 的值是對會話還是對應用程式域是全域的?
Public Class AuthenticationClient
Private Shared Property ClientKey As String
Get
Return HttpContext.Current.Session("ClientKey")
End Get
Set(value As String)
HttpContext.Current.Session("ClientKey") = value
End Set
End Property
'The function below is called only once on the FormsAuth login page for each successful login attempt
Public Shared Sub SetClientKeyForSession(clientKeyForSession As String)
ClientKey = clientKeyForSession
End Sub
'This can be called for multiple contacts
Public Shared Async Sub SaveSomething(userId As Integer)
Await SomeDataAccess.SaveThisAsync(userId, ClientKey) '<- Not Me.ClientKey but is it the same session value set at login, I assume yes.
End Sub
....
End Class
uj5u.com熱心網友回復:
屬性只是獲取和設定方法。它是應用程式域共享的靜態欄位。由于您沒有欄位(僅將會話變數包裝在 get 和 set 方法中),因此所有內容都限定為會話。
請注意,自動屬性(例如Shared Property MyString As String在 VB 中)實際上會創建您看不到的支持欄位。但這不是您在這里所做的,因此沒有創建支持欄位,也沒有使用靜態資料。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/409727.html
標籤:
上一篇:VBGetfiles排除
下一篇:來自VB.NET的C#委托
