【发布时间】:2009-12-21 18:12:11
【问题描述】:
我继承了一些非常古老的 ASP.Net 代码。最初在 1.0 中编写,然后转换为 2.0 有一个使用自定义寻呼机控件的页面。该控件具有以下逻辑:
Private _DataSource As PagedDataSource
Public Property DataSource() As PagedDataSource
Get
If Not IsNothing(Session("DataSource")) Then
_DataSource = Session("DataSource")
Return _DataSource
End If
Return Nothing
End Get
Set(ByVal value As PagedDataSource)
_DataSource = value
If Not IsNothing(value) Then
Session("DataSource") = value
Else
Session("DataSource") = Nothing
End If
End Set
End Property
使用该寻呼机的页面中包含以下逻辑:
Private PagedData As PagedDataSource
Private Function GetData() As DataTable
Dim DT As New DataTable
Dim CategoryID As Integer = -1
If IsNothing(ddlCategories.SelectedValue) OrElse Not Integer.TryParse (ddlCategories.SelectedValue, CategoryID) Then
CategoryID = -1
End If
Dim myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
Dim myAdapter As New SqlDataAdapter
myAdapter = New SqlDataAdapter("SearchResources", myConnection)
myAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
If SearchText <> String.Empty Then
trFiltered.Visible = True
End If
With myAdapter.SelectCommand.Parameters
.AddWithValue("@CategoryID", CategoryID)
.AddWithValue("@SearchText", SearchText)
.AddWithValue("@CompanyID", CompanyID)
End With
If Not Security.IsSiteAdmin Then
myAdapter.SelectCommand.Parameters.AddWithValue("@UserIsAdmin", 0)
myAdapter.SelectCommand.Parameters.AddWithValue("@FTPUserID", Security.GetUserID(Context.User.Identity.Name))
Else
myAdapter.SelectCommand.Parameters.AddWithValue("@UserIsAdmin", 1)
End If
Try
myAdapter.Fill(DT)
Catch ex As Exception
ErrorLog.LogError(ex.Message, ex.StackTrace, HttpContext.Current.User.Identity.Name, HttpContext.Current.Request.Url.ToString)
HttpContext.Current.Response.Redirect("~/error.aspx", False)
Return Nothing
End Try
Return DT
End Function
Protected Sub ReloadData()
CurrentPage = 0
CheckFilters()
BindData()
End Sub
手头的任务是删除所有会话变量。在不使用会话的情况下表示这些数据的最佳方式是什么?最初我被告知将所有会话项目放入一个 cookie 中,虽然这适用于大多数项目,但由于 cookie 大小限制,它不适用于此,我也不热衷于将其保留在 ViewState 中的想法,或者即使这是一个选择。我对 VB 很陌生,对重写遗留代码没有太多经验。会话不是一个选项,因为它正在被移动到网络场中,并且粘性会话已关闭,因此它必须在没有会话的情况下工作。
非常感谢任何建议。对不起,如果我问了一个答案很明显的问题。
提前致谢, -詹姆士。
【问题讨论】: