Accessing Static Variables From Global.asax In Aspx.cs Pages?

Feb 13, 2011

i declared a static variable in global.asax file like below

<%@ Application Language="C#" %>
<script runat="server">
static string Sv;
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}

i want to access this variable in aspx page. how can i access this variable.

View 2 Replies


Similar Messages:

C# - Dictionary Lookup Efficiency & Request Scoped Global Variable Accessible By Global.asax And Pages/etc?

Feb 8, 2011

I know there is a couple answered questions on here regarding "request scoped" globals, but I want to nit-pick on something specifically and maybe squeeze some extra enlightenment out of one or two of you.I have an ASP.NET C# Website and a static Dictionary of objects (loaded from DB once on Application start). Each page request will need to do a lookup in the Dictionary (based on a key derived from the request url/etc) and get the appropriate object.The issue is I'm trying to maximize efficiency by reducing the lookups to the Dictionary per Request. Doing just a single lookup within a Page itself is easy enough and I can pass the object to sub controls, etc too.. but global.asax is separate from the Page and it also needs to use the object (in Application_BeginRequest and Session_Start).

So is doing a Dictionary lookup once in Application_BeginRequest, once (when necessary) in Session_Start and once in the Page negligible speed wise, even if there are many requests coming in every second?I would like it if I could just have a Request scoped global variable that I can easily call upon.. the only one I see available though is HttpContext.Current.Items and that is a Dictionary itself.Am I beingridiculously nit-picky with my concern over efficiency? or will these milliseconds (nanoseconds?) get me in the long run when more and more requests are being made?

PS. I currently only have around 100 objects in the Dictionary although this may increase in the future.

View 2 Replies

Access Global.asax Static Members?

Dec 30, 2010

If we declare a static variable in Global.asax then how to access it inside an ASP.NET page ?

<script runat=server">
public static object myObject = new MyClass();
// Application_Start() and other stuff goes here.
</script>

And, is this a good idea for storing a global object (same instance for all requests) ?

View 3 Replies

C# - Static ChannelFactory In Global.asax.cs Throws CommunicationObjectFaultedException?

Jul 21, 2010

I am using the following code in my Global.asax.cs file:

public static readonly IMyCommunicationService GlobalCommunicationChannel =
new ChannelFactory<IMyCommunicationService>("NetTcpBinding_IMyCommunicationService").CreateChannel();

From every website I am accessing the static var "GlobalCommunicationChannel".

That is working very well so far. But sometimes, in production environment, I am getting an CommunicationObjectFaultedException. It says that I can not use my GlobalCommunicationChannel object as the object "System.ServiceModel.Channels.ServiceChannel" is in faulted-state.

I get no more information than that. After some minutes it is working again. Don't know why. I think the connection is re-established or something like that.

What causes this error? Is there a way to avoid this error in future without adding a try/catch and a retry everywhere?

View 1 Replies

State Management :: Using Global.asax To Set Session Variables Pulled From SQLServer?

Sep 3, 2010

I have a custom class that pulls user information from a SQL Server table. Now that I'm expanding the site from a single page to others. I want to shift the code to the Session_Start event so that the information is always loaded when the site is accessed. How do I call my custom code from global.asax since its script and not a class.

View 5 Replies

Web Forms :: Accessing Static Variable In Global.ashx File?

Sep 28, 2010

I want to access the static variable in my global.ashx file I am using classname.variable name for accessing the variable but the variable name dose not appear.Can someone tell me how to access static varialbe in *.ashx file.

View 5 Replies

How To Pass Aspx Page In Global.asax

May 28, 2010

I am categorizing my website page to be defined as Secured & unsecured (ie few page on http & other on https) in Global.asax. Now, Product.aspx page has to be defined as unsecured. But I just couldn't make out how to define this since it is called with a querystring. If I simply define it as "Product.aspx", output is coming incorrect ie I need to define it as "Product.aspx?pid=123". But since there are lot many products, so I couldn't define it like this.

View 2 Replies

Working With Static Variables / Store The User Specific Information In Static Variables?

Mar 5, 2011

whats the exact use of static variables in overall programming in .net and for asp.net...

Recently i went for the interview where interviewer asked me 2 question which i was not sure for the same..

whats the use of session object, i said sessions are the server side object, they are used when you want to store user specific data at server side, then he asked what if i want to use static variables for the same, i was mum, can anyone tell me how asp.net will behave if i store the user specific information in static variables.If i use cookies which are the best option to store the data at client side (not sensitive one), but what if user has disabled cookies on his machine, will my application would crash.

View 3 Replies

Added The .aspx Extension To The Controller In My Global.asax File?

Oct 15, 2010

Has anyone had any luck getting MVC 3 working on IIS 6?I've added the .aspx extension to the controller in my global.asax file. I also have Default.aspx in the root of the project with the following code-behind:

[Code]....

This is what my global.asax looks like:

[Code]....

.NET 4.0 has been installed on the server, and is selected for the project. All of this, and I still get HTTP Error 404 -

View 8 Replies

Web Forms :: Declare Global Variables That Are Accessible On All Pages

Jan 9, 2014

it's possible to declear global variable in asp.net C#.

View 1 Replies

Where The Static Variables Are Stored In Aspx Page

Apr 4, 2011

Possible Duplicate: Where are static variables stored in asp.net aspx page Hi can someone please tell me where the static variables are stored in asp.net aspx page.Is it in the view state? If so I guess you wouldn't want to stored big complex objects?

View 1 Replies

Web Forms :: How To Call Global.asax Method When An Exception Occurred On Aspx Page

Mar 12, 2010

my objective is i want to log all those exceptions on my aspx pages which are handled or unhandled. To do this do i need to write my method in global.asax or how can i do that?

View 1 Replies

Where Are Static Variables Stored In Aspx Page / Is It In The View State

Apr 4, 2011

where the static variables are stored in asp.net aspx page.Is it in the view state? If so I guess you wouldn't want to stored big complex objects?

View 2 Replies

State Management :: Accessing Variables Across Pages Within The Same Session?

Jul 12, 2010

How can I retain the value of variables that I fill from CodeBehind throughout the session? (C#). For example, I do a LINQ query from the log in "on-Click" button event. The query produces a bunch of data about the user that I want to access throughout the session on additional ASP pages. I know that I can pass a large query string but I suspect that there is a better way. Here's a specific...

from the db function I product: COS=2 (class of service). Throughout the session, I test for COS and display appropriate pages. Assume that the LINQ query is accomplished in the CodeBehind attached to the "loginButton" within the "login.aspx" page.

View 3 Replies

C# - Is It Safe To Access .net Session Variables Through Static Properties Of A Static Object

May 10, 2010

Is it safe to access asp.net session variables through static properties of a static object?Here is what I mean:

public static class SessionHelper
{
public static int Age
{
get
{
[code]...

Is it possible that userA could access userB's session data this way?

View 2 Replies

How To Setup Login Control For Accessing Aspx Pages In Intranet

Feb 3, 2010

i need to setup login control for accessing my aspx pages in intranet

how to do that?

View 2 Replies

C# - How Can We Use Global.asax

Feb 26, 2010

how can we use global.asax in asp.net? and what is that?

View 4 Replies

Global.asax With SQL?

Jun 20, 2010

Is it possible in the global.asax file on session_start to check if a url string exists and it it does insert the string into a sql database? The url would be something link http://www.mysite.com?campaign=january.

I would want to capture the january bit and put that in the database for each visitor that uses that url.

View 3 Replies

Web Forms :: What Is Global.asax / How To Use It

Jan 27, 2010

I want to make All Methods about Error handling in asp.net some one device me at using global.asax what is global.asax?

how can i use it ?

View 1 Replies

Configuration :: Global.asax 3.5?

May 12, 2010

I have a hosting account on DailyRazor.com , i use Global.asax in my project to start a schedule process in Application_Start.When i just publish my website, and upload it, the Application_Start does not Fire, but when i upload the Global.asax to my host it gives an Error but the Applicaiton_Start Event fires up, and then i delete the Global.asax file and everything works.just wondering, What am doing wrong ? or why this meaningless thing happens?

View 2 Replies

C# - Global.asax Application_BeginRequest

Nov 4, 2010

I have a site with multiple domains pointing to it. I wanted to redirect all requests to main domain so I've created a method called RedirectToRealDomain("domain.com") to check and redirect all requests to my preferred domainAt the moment it lives on Session_Start but I am planing to move it to Application_BeginRequest event. As I understand Session_Start only raised when new session started but Application_BeginRequest raised on all requests. RedirectToRealDomain method doesn't do any DB lookups or anything expensive apart from comparing strings.

View 2 Replies

Set Masterpage From Global.asax?

May 21, 2010

I want to set the Masterpage property in Global.asax.

This is what I have done but I get a NullReferenceException on the first line.

protected void Application_PreSendRequestContent(Object sender, EventArgs e)
{
System.Web.UI.Page page = System.Web.HttpContext.Current.Handler as System.Web.UI.Page;
if (Session["lang"] == "eng")
{
page.MasterPageFile = "SideMasterPageEng.master";
}
}

View 1 Replies

.net - Get Username In Global Asax?

Jun 29, 2010

I am trying to check if the user belongs to someone's friendlist from the database and redirect him accordingly.I am doing this in a routehandler called by Global Asax.I just want to know how to get the username (from the login information) in the route handler class (or Global asax)I used this: string username = HttpContext.Current.User.Identity.Name; and very strangely, its assigning ".aspx" as the username!! ps: i did search for similar question but in vain.

View 1 Replies

Vb.net - To Rewrite Url In Global.asax?

Oct 19, 2010

I need replace double slashes in one slash. I am planning do this in Global.asax Application_BeginRequest event. Is it enough? or better do a http module?

UPD
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request

[code]...

View 1 Replies

Some Basic Clarification On Global.asax?

Feb 8, 2010

I was under the impression till now that Global.asax is used for application level events and it's a common file for all users. Then what does Session_Start event does in this file. If we have to create user session varaibles then Is this the write place to create those? If someone can kindly clear my confusion on this file and it's methods.

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved