Hello!
I tried to use Application State as given in MSDN ( http://msdn.microsoft.com/en-us/library/ms178594.aspx):
I opened a WebApplicaion (C#) in Visual Studio 2008 and added Global.asax file.
And added the following code (from MSDN) in Global.asax: -
<%@ Application Codebehind="Global.asax.cs" Inherits="WebApplication1.Global" Language="C#" %>
-
<object runat="server" scope="application" ID="MyInfo"
-
PROGID="MSWC.MYINFO">
-
</object>
-
Just to check, when I run the application I get the following error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Cannot load type with ProgID 'MSWC.MYINFO'.
Source Error:
Line 1: <%@ Application Codebehind="Glo bal.asax.cs" Inherits="WebAp plication1.Glob al" Language="C#" %>
Line 2: <object runat="server" scope="applicat ion" ID="MyInfo"
Line 3: PROGID="MSWC.MY INFO">
Line 4: </object>
Source File: /global.asax Line: 2
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.507 27.3603; ASP.NET Version:2.0.507 27.3082
Please help.
Thanks.
3 3297
I hope you have noticed this line in MSDN :
"You can use application state in two ways. You can add, access, or remove values from the Contents collection directly through code. The HttpApplication State class can be accessed at any time during the life of an application. However, it is often useful to load application state data when the application starts. "
You're going second way, no matter, but you need to access Application object through the Page_Load method by this code in any page: - protected void Page_Load(Object sender, EventArgs e)
-
{
-
Label1.Text = MyInfo.Title;
-
}
-
Have you tried that?
I want to use object in Global.asax: - <object runat="server" scope="application" ID="MyInfo"
-
PROGID="MSWC.MYINFO">
-
</object>
If I use this code, the I get Parser Error Message: Cannot load type with ProgID 'MSWC.MYINFO'.
Can you give me the right code for Global.asax and Default.aspx.cs ?
Try this code in Global.asax : - <%@ Application Language="C#" %>
-
-
<script runat="server">
-
-
void Application_Start(object sender, EventArgs e)
-
{
-
// Code that runs on application startup
-
Application.Add("count", 0);
-
Application.Add("PageView", 0);
-
}
-
-
void Application_End(object sender, EventArgs e)
-
{
-
// Code that runs on application shutdown
-
-
}
-
-
void Application_Error(object sender, EventArgs e)
-
{
-
// Code that runs when an unhandled error occurs
-
-
}
-
-
void Session_Start(object sender, EventArgs e)
-
{
-
// Code that runs when a new session is started
-
try
-
{
-
int PageView = int.Parse(Application.Get("PageView").ToString());
-
PageView++;
-
Application.Set("PageView", PageView);
-
}
-
catch (Exception ex)
-
{
-
Response.Write(ex);
-
}
-
Session.Add("somevalue", Session.SessionID);
-
}
-
-
void Session_End(object sender, EventArgs e)
-
{
-
// Code that runs when a session ends.
-
// Note: The Session_End event is raised only when the sessionstate mode
-
// is set to InProc in the Web.config file. If session mode is set to StateServer
-
// or SQLServer, the event is not raised.
-
int PageView = int.Parse(Application.Get("PageView").ToString());
-
PageView--;
-
Application.Set("PageView", PageView);
-
-
}
-
-
</script>
-
And in Default.aspx.cs use this code: - using System;
-
using System.Configuration;
-
using System.Data;
-
using System.Linq;
-
using System.Web;
-
using System.Web.Security;
-
using System.Web.UI;
-
using System.Web.UI.HtmlControls;
-
using System.Web.UI.WebControls;
-
using System.Web.UI.WebControls.WebParts;
-
using System.Xml.Linq;
-
-
public partial class _Default : System.Web.UI.Page
-
{
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
if (Page.IsPostBack == true)
-
{
-
Label1.Text = string.Format("Original: " + Application["count"]);
-
ViewState.Add("ViewStateItem", "Hello World" );
-
}
-
Label3.Text = "Page Viewed so far...." + Application.Get("PageView").ToString();
-
//Response.Write("Page Viewed so far...." + Application.Get("PageView").ToString());
-
}
-
protected void Button1_Click(object sender, EventArgs e)
-
{
-
int Count = (int)Application["count"];
-
Count++;
-
Application["count"] = Count;
-
Label2.Text = String.Format("Updated: {0}", Application["count"]);
-
//Label4.Text = ViewState["ViewStateItem"].ToString();
-
Label4.Text = Session["somevalue"].ToString();
-
}
-
}
-
In Default.aspx I used a button and 4 Labels whose text properties hold the Application and Session State values.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: orekin |
last post by:
Hi There
I have been trying to come to grips with Application.Run(),
Application.Exit() and the Message Pump and I would really appreciate
some feedback on the following questions .. There are quite a few
words in this post but the questions are actually quite similar and
should be fairly quick to answer ...
(1) What is Happening with the Threads
|
by: Brett |
last post by:
I am working with vb.net in a asp.net application.
I have created a config file in xml format. The goal is to
be able to change the config file without having to recompile the
entire
application.
So when the Application starts I read the xml file and place
each key-value pair into a Synchronized hash table. Now I want to
save this hashtable to Application state for quick access and also so
I don't have to open the config file a...
|
by: Grinninger |
last post by:
Hello,
I am using ASP.NET, C# under W2K.
I try to keep some important information in application- and
session-state Objects.
With the recycling of the ASPNet_WP.EXE my application- and
session-state Objects get lost.
Therfore I have some questions:
-) Is it usual that the ASPNet_WP.EXE becomes recycled twice a day?
-) What is the expected recyclingperiod for the ASPNet_WP.EXE ?
|
by: Bruce W.1 |
last post by:
I'm storing some things in the application state, like this:
Application = "whatever";
In Visual Studio, when I shut down the web app then start it again the
application state information remains. If there are no browsers using
the app one would think that this would remove any application state,
but it does not.
However if I wait awhile then the application state information goes
away.
|
by: BB |
last post by:
Hello all,
I might be missing something here, but am trying to understand the difference between using application-level variables--i.e. Application("MyVar")--and global variables--i.e. public myVar as string, etc. It seems to me that the scope and duration are the same, as they both are there while the application is running, and both go away when it quits. I presume that one difference is that the application state can be "flushed," such...
| |
by: Anthony P. Mancini |
last post by:
I'm working on a proof of concept that will ultimately be deployed on a load
balancer.
For the sake of a preliminary demonstration I created a C# object and marked
it's attributes
as Public Shared Static. I also set the EnableSessions and EnableViewState
Page directives
to false. Here's the part that stumped me :
as I was moving from page to page within the demo, I accidently realized the
data I dropped
|
by: Mel |
last post by:
This may be a stupid question, but here goes...
I have created a NameValueCollection in my website's application state. If,
during a page request, I add a string key and string value to the
collection, how are they stored? Strings are objects so I'm really only
passing references, right? Now I assume that request handlers run in
different threads with their own memory spaces, and when the request ends,
the memory space is unaloted,...
|
by: Eric McVicker |
last post by:
Session state has options to be inproc, state server or sql server. Why does
Application state not allow for state server or sql server so the same
Application state could be shared between servers in a farm?
|
by: spacehopper_man |
last post by:
I'm considering ditching all use of Session state in favour of
Application state.
This is because - from what I can work out - it will be more memory
efficient for me.
I have three questions:
1) When is memory used for Session State freed (or essentially freed)?
- if ever...
|
by: =?Utf-8?B?SkhhbGV5?= |
last post by:
Our system is:
IIS Server: dual Intel Xeon 2.80 GHz, 4 GB Ram
Windows Server 2003 SP2
IIS 6.0
SQL Server: dual Intel Xeon 2.80 GHz, 4 GB Ram (separate server)
Windows Server 2003 SP2
SQL Server 2000
We are having some problems with a website we are developing, and had some
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |