简体   繁体   English

Global.asax页面? 在Asp.net?

[英]Global.asax page ? In Asp.net?

In web application [asp.net] shall we write code that can retrive data from datbase or insert something in database. 在Web应用程序[asp.net]中,我们应该编写可以从数据库中检索数据或在数据库中插入内容的代码。 in any event of global.asax. 无论如何都是global.asax。 when i am writing code in "Application_BeginRequest" even like : 当我在“Application_BeginRequest”中编写代码时,即使:

Session["abc"]= 10; 会话[“abc”] = 10; it is throwing exception that session can't declare some thing.Session state is not available in this context. 它抛出了会话无法声明某些东西的异常。在这种情况下,该状态不可用。

Oh. 哦。 You need to read about ASP.NET page cycle 您需要阅读有关ASP.NET页面循环的信息

Then You will realize that Session state is not available on BeginRequest 然后您将意识到BeginRequest上没有Session状态

Assuming I am understanding your question correctly then you are right that you cannot access session in that event. 假设我正确地理解了您的问题,那么您在该事件中无法访问会话是正确的。 Try instead putting it in Application.AcquireRequestState . 尝试将其放在Application.AcquireRequestState中 This is where ASP.NET sets up session and such like. 这是ASP.NET设置会话等的地方。

What you can use in BeginRequest is the Context which is acceesible in that request if you just need to set up data for just that request. 您可以在BeginRequest中使用的是Context ,如果您只需要为该请求设置数据,则该请求中可以加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM