ASP.NET 2.0: Global.asax Design Surface Gone

M

Mark Olbert

I have several ASP.NET 1.1 websites where I centralized a read-only dataset (i.e., one which no web page ever changed) and its
associated SqlDataAdapters.

In 2.0 I noticed that the Global.asax file does not have a design surface, so I can't drag and drop database components onto it.

I could configure all this stuff manually, but that would be a lot of work duplicating what the visual designers do just fine.
Besides, it would put me way behind the curve on getting that promised 70% productivity improvement that I'm guaranteed by switching
to ASP.NET 2.0 :).

Is there a way to use the visual database tools in ASP.NET 2.0 in a global setting for a website?

- Mark
 
S

Steven Cheng[MSFT]

Hi Mark,

Welcome to ASPNET newsgroup.
As for the global.asax file component designing problem, yes, in asp.net
2.0/vs2005, the global.asax has changed to not use code behind(all code be
put in asax file by default). Also, ASP.NET 2.0 page no longer mainly rely
on component (draged droped on component designer for page). For data
accessing, we use the DataSource controls instead of the Components
(DataAdapter and DataSet....). And for your scenario, you need get a
global scope DataSet to let other pages read the static datas, you can use
the new VS 2005 DataSet wizard to create a TypedDataSet , the new typed
DataSet wizard will also help us create a TableAdapter, which simplifies
the code for creating TypedDataset, e.g:

suppose we've created the following DataSet and TableAdapter:
(the code will be put in App_code dir)

DataSet1, CategoriesTableAdapter, then we can just use the below code to
create the global dataset in Application_Start event


void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
DataSet1TableAdapters.CategoriesTableAdapter adapter = new
DataSet1TableAdapters.CategoriesTableAdapter();
DataSet1 ds1 = new DataSet1();
adapter.Fill(ds1.Categories);

Application["g_data"] = ds1;
}

this is what is being easied through the net TableAdapter components.....
So the original work in asp.net 1.1/vs2003 is not divided into to parts:

1. Use IDE wizard to create the typedDataSet and TableAdapter,

2. Use the TableAdapter to get the TypedDataSet instance ....

Here are some msdn reference about the TableAdapter:


#TableAdapter Overview
http://msdn2.microsoft.com/en-us/library/bz9tthwx.aspx

#TableAdapter Configuration Wizard
http://msdn2.microsoft.com/en-us/library/dex7k4dw.aspx

#How to: Create TableAdapters
http://msdn2.microsoft.com/en-us/library/6sb6kb28.aspx

Thanks & Merry Christmas,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)






--------------------
| NNTP-Posting-Date: Fri, 23 Dec 2005 00:05:14 -0600
| From: Mark Olbert <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Subject: ASP.NET 2.0: Global.asax Design Surface Gone
| Date: Thu, 22 Dec 2005 22:05:14 -0800
| Organization: Olbert & McHugh, LLC
| Reply-To: (e-mail address removed)
| Message-ID: <[email protected]>
| X-Newsreader: Forte Agent 3.1/32.783
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Lines: 12
| X-Trace:
sv3-5Ntq93RzHckZwcpyWNViHv0C5LXsgfulNlvYZG8LBTIms4iqnfyXGL77l/orNaiRDiHQVShl
mtlY0sx!EOtCFvuEclp6p544nSH9cV0rVTIPp2hi5ArOtF2EIpsdi6DrPyi6J5lK324SmvHHSpRw
cw==
| X-Complaints-To: (e-mail address removed)
| X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
| X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
| X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your
complaint properly
| X-Postfilter: 1.3.32
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onli
ne.de!border2.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.gigan
ews.com!local01.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:366726
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I have several ASP.NET 1.1 websites where I centralized a read-only
dataset (i.e., one which no web page ever changed) and its
| associated SqlDataAdapters.
|
| In 2.0 I noticed that the Global.asax file does not have a design
surface, so I can't drag and drop database components onto it.
|
| I could configure all this stuff manually, but that would be a lot of
work duplicating what the visual designers do just fine.
| Besides, it would put me way behind the curve on getting that promised
70% productivity improvement that I'm guaranteed by switching
| to ASP.NET 2.0 :).
|
| Is there a way to use the visual database tools in ASP.NET 2.0 in a
global setting for a website?
|
| - Mark
|
 
M

Mark Olbert

Steven,

Something's not right with the approach you suggested:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
DataSet1TableAdapters.CategoriesTableAdapter adapter = new
DataSet1TableAdapters.CategoriesTableAdapter();
DataSet1 ds1 = new DataSet1();
adapter.Fill(ds1.Categories);

Application["g_data"] = ds1;
}

If I take your approach, and try to access ds1 in the website using something like this:

DataSet1 GetDataSet1()
{
return (DataSet1) Application["g_data"];
}

an exception gets thrown because the Application object is null. Session won't work either, because the Session object is "...not
available in this context".

So where/how do I persist application-wide data?

And, while I'm at it, why in the world did Microsoft think it was a bright idea to so radically change the model for ASP.NET that it
broke every single website I've built in the last two and a half years????

Frankly, this new version of ASP.NET leaves a LOT to be desired.

- Mark
 
S

Steven Cheng[MSFT]

Thanks for your response Mark,

From the error you mentioned, seems the context your code executed can not
access the ApplicationState. Genearlly the ApplicaionState of an ASP.NET
application is available to all the pages, and the "Application" member
proeprty is associated with Page class and the Global class, so where did
you put the following code?

DataSet1 GetDataSet1()
{
return (DataSet1) Application["g_data"];
}

Anyway, we can get the current ASP.NET application's ApplicationState
through

HttpContext.Current.Application (HttpContext.Current represent the
current execting worker thread's associated HttpContext...)


In addition, we also have some other approachs to provide application-wide
data, e.g:

using a certain class's static member property , or use the ASP.NET
Application Cache,

HttpContext.Current.Cache....

Also, these variables are not available out of the ASP.NET page's
serverside lifecycle , so we need to make sure our code(referencing them
are in the correct scope....).

Please feel free to post here if there're anything unclear or need any
further assistance..

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)





--------------------
| NNTP-Posting-Date: Fri, 23 Dec 2005 13:26:52 -0600
| From: Mark Olbert <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Subject: Re: ASP.NET 2.0: Global.asax Design Surface Gone
| Date: Fri, 23 Dec 2005 11:26:52 -0800
| Organization: Olbert & McHugh, LLC
| Reply-To: (e-mail address removed)
| Message-ID: <[email protected]>
| References: <[email protected]>
<[email protected]>
| X-Newsreader: Forte Agent 3.1/32.783
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Lines: 33
| X-Trace:
sv3-X6cP5YBOWrdZgQ+7stoWYDwdlFOMVPLFgTlJu9YWANDk8cQh4ou00XfNyhs9pyWjvj8N7KNg
CSyFxg6!6w6ocRZiSY1iqPcwYX8BT5og6E9bNGPwDsiY9aY4QjXDGdUQw8B820JYMeVEM3VWN6rE
dg==
| X-Complaints-To: (e-mail address removed)
| X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
| X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
| X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your
complaint properly
| X-Postfilter: 1.3.32
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onli
ne.de!border2.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.gigan
ews.com!local01.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:366834
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Steven,
|
| Something's not right with the approach you suggested:
|
| > void Application_Start(object sender, EventArgs e)
| > {
| > // Code that runs on application startup
| > DataSet1TableAdapters.CategoriesTableAdapter adapter = new
| >DataSet1TableAdapters.CategoriesTableAdapter();
| > DataSet1 ds1 = new DataSet1();
| > adapter.Fill(ds1.Categories);
| >
| > Application["g_data"] = ds1;
| > }
|
| If I take your approach, and try to access ds1 in the website using
something like this:
|
| DataSet1 GetDataSet1()
| {
| return (DataSet1) Application["g_data"];
| }
|
| an exception gets thrown because the Application object is null. Session
won't work either, because the Session object is "...not
| available in this context".
|
| So where/how do I persist application-wide data?
|
| And, while I'm at it, why in the world did Microsoft think it was a
bright idea to so radically change the model for ASP.NET that it
| broke every single website I've built in the last two and a half years????
|
| Frankly, this new version of ASP.NET leaves a LOT to be desired.
|
| - Mark
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top