473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

global.asax in v2

I notice that the global.asax in v2 is inline. because of this I can't say
Session["mysessionvar"] = conn;

The compiler will accept it but at runtime the exception says "Session State
is not available in this context".

Is this a downgrade feature from 1.1?

--
Regards,
Gary Blakely
Jun 25 '06 #1
1 1447
Are you writing that in Session_OnStart ( or Session_Start ) ?
If so, and if you define "conn" before you define Session["mysessionvar"], it should work.

public void Session_OnStart()
{
string conn = "someconnection string";
Session["mysessionvar"] = conn;
}

Do you have session state enabled ? If you do...that should work.

btw, you can always continue to use codebehind in global.asax.

There's nothing stopping you.

Just create the global.asax.cs file in the App_Code directory
....and code away...in both global.asax and global.asax.cs.

Make sure that Global inherits from HttpApplication in global.asax.cs :

public class Global : HttpApplication
{
public Global()
{
}
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
//
// TODO: Add constructor logic for other Application events here
//
}
}

Make sure you Import all the classes you need in global.asax.cs
and... in global.asax...you'll need this directive :

<%@ Application Language="C#" Inherits="Global" %>

That's it!
You can continue to blissfully code the way you're used to.

Quite frankly, I don't know why you'd want to do that,
since in global.asax you *can* do anything you can do in global.asax.cs
without needing to double-compile your global.code but, hey, we aim to please!

:-)

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"GaryDean" <Ga******@newsgroups.nospam> wrote in message
news:eB**************@TK2MSFTNGP05.phx.gbl...
I notice that the global.asax in v2 is inline. because of this I can't say Session["mysessionvar"]
= conn;

The compiler will accept it but at runtime the exception says "Session State is not available in
this context".

Is this a downgrade feature from 1.1?

--
Regards,
Gary Blakely



Jun 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: fd123456 | last post by:
Hi Tom ! Sorry about the messy quoting, Google is playing tricks on me at the moment. > Global.asax is where you normally have the Global Application > and Session variables and code to...
12
by: John M | last post by:
Hello, On Microsoft Visual Studio .NET 2003, I want to use some global elements, that can be used in each one of my pages. i.e I put a oleDBConnection on global.asax.vb How can I use it...
8
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical...
5
by: ad | last post by:
The Global.asax is code-inside with default. How to change Global.asax to code-behind?
2
by: Steve | last post by:
I am new to this newsgroup & to .NET in general. I have been playing around with Visual Studio .NET, building and rendering web pages using VB "code behind" files. My problem / question is; How...
11
by: Ron | last post by:
I have a web project compiled with the new "Web Deployment Projects" plugin for VS2005. I'm deploying the web project to one assembly and with updateable option set to ON. When I'm running the...
4
by: Al Santino | last post by:
Hello, I've created a simple C# web services project using Visual Studio 2005. My service compiles and runs correctly when called by remote clients. I'm able to step through the service in the...
16
by: thefritz_j | last post by:
We just converted our VS2003 1.1 VB web project (which was working fine) to VS2005 2.0 and now I get: Parser Error Message: Could not load type '<Namespace>.'. Source Error: Line 1: <%@...
8
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project...
15
by: =?Utf-8?B?UGF0Qg==?= | last post by:
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax code file. In 1.1 I could have a code behind file for the global.asax file. This allow for shared variables of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.