asp中的session到asp.net后就丢弃了。

dbx 2003-09-07 06:01:54
asp登录
得到session("user_id") ="XXXX"
asp.net页面装载中。
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Session("user_id") = "SAFDSAF"
If Session("user_id") = "" Then
' Session.Item("user_id")
Response.Write("服务器超时,请重新登录")
' Response.Write(Session.SessionID)
' Response.End()
End If

End Sub

session就不见了。asp与asp.net都是运行在同一台机器上。
...全文
27 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
dbx 2003-09-07
  • 打赏
  • 举报
回复
但是asp的session没有拿到呀
dbx 2003-09-07
  • 打赏
  • 举报
回复
C#里有Session.Item("user_id").ToString()这种转换吗?在vb里就没有.

好的。
jjcccc 2003-09-07
  • 打赏
  • 举报
回复
If Session.Item("user_id").ToString()=null or Session.Item("user_id").ToString()= "" Then
Response.Write("服务器超时,请重新登录")

Response.End()
End If
我不用VB,语法不一定对!意思是要考虑到Session.Item("user_id")等于空值的情况。(超时后,就为空了,也就引发你的异常信息!)
dbx 2003-09-07
  • 打赏
  • 举报
回复
如下

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Session.Item("user_id").ToString() = "" Then
Response.Write("服务器超时,请重新登录")

Response.End()
End If

Dim datetime1 As DateTime
If Not Page.IsPostBack Then
Dim i As Integer
For i = 1 To 12
Dim listitems As New ListItem
listitems.Text = i & "月"
listitems.Value = i
If Month(Now) = i Then listitems.Selected = True
Dp2.Items.Add(listitems)
Next
For i = 2000 To 2006
Dim listitems As New ListItem
listitems.Text = i & "年"
listitems.Value = i
If Year(Now) = i Then listitems.Selected = True
Dp1.Items.Add(listitems)
Next
'+++++++++++++++++++++++++++++++++++++

datetime1 = DateTime.Parse(Dp1.SelectedItem.Value & "-" & Dp2.SelectedItem.Value & "-1")

lbldate.Text = DateTime.Now.Date
import.HRef = "print.aspx?datetime1=" & datetime1
company_report.HRef = "report.aspx?datetime1=" & datetime1

'++++++++++++++++++++++++++
getdatabind("e_gather", datetime1)
End If
datetime1 = DateTime.Parse(Dp1.SelectedItem.Value & "-" & Dp2.SelectedItem.Value & "-1")
company_report.HRef = "report.aspx?datetime1=" & datetime1
End Sub

Private Sub getdatabind(ByVal str As String, ByVal datetime1 As DateTime)

'绑定数据,确定汇总时间。
rp1.DataSource = func1.getDataReader_Proc(str, datetime1)
rp1.DataBind()
End Sub

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
jjcccc 2003-09-07
  • 打赏
  • 举报
回复
先把你的web.config里的
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
改成:
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
然后就看到页面上显示出的真正错误信息。
dbx 2003-09-07
  • 打赏
  • 举报
回复
代码如下。

Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".


<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.


<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>

jjcccc 2003-09-07
  • 打赏
  • 举报
回复
什么错?
dbx 2003-09-07
  • 打赏
  • 举报
回复
up
dbx 2003-09-07
  • 打赏
  • 举报
回复
不行呀,我试过了,出错呀。
cnlamar 2003-09-07
  • 打赏
  • 举报
回复
好象本来就不通用
jjcccc 2003-09-07
  • 打赏
  • 举报
回复
因为Session("user_id")是Object类型
dbx 2003-09-07
  • 打赏
  • 举报
回复
为什么要用toString()这个方法。
jjcccc 2003-09-07
  • 打赏
  • 举报
回复
If Session("user_id").Tostring() = "" Then
' Session.Item("user_id")
Response.Write("服务器超时,请重新登录")
' Response.Write(Session.SessionID)
' Response.End()
End If

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧