Unfortunately, no. The "as DAL" in there will blow up without a using at the top of the page. The first approach I suggested should work without a using though.
I created a Global.cs file and placed it in my app_code directory. I assigned my instances and variables as public static members...
using System;
using System.MyDLL.Server.DAL;
using System.Configuration;
public static class Global
{
public static Exception ex = null;
public static DAL dal = new DAL();
public static string ConnectionString = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
public static void SetConnectionString()
{
dal.ConnectionString = ConnectionString;
}
}
For the sake of keeping my connection string available on every page I called the SetConnectionString (above) function,
@{
Global.SetConnectionString();
}
Becuase of the public static members in Global.cs I can call my instanced dal without creating a new instance of dal (this was done in Global.cs)
Global.dal.object;
void myfunction(Global.something, out Global.ex);
In conclusion,
By first created a public static class I can use it throughout my project...
nenvy.com
zettersten.com
client side dev
canvas/html5/js/css
Marked as answer by erik5388 on Sep 03, 2010 02:27 PM
I am almost completely sure that won't scale and you'll have issues when requests start coming in fast and each request is hitting the same variable. Your object should really be instantiated per request (stuffed in Context.Items or something that lives
for the life of the request)...for now.
We're finishing up new simplified state management for the next release that will make what you're trying to do, much easier. Basically, you'll be able to say Page.dal = new DAL(); and set all your initial properties you need in _Init.cshtml, then in any
web page you can access Page.dal. Simple. :)
HumanCompile...
Member
511 Points
100 Posts
Microsoft
Re: How to add WebMatrix default parameters?
Aug 11, 2010 11:17 PM|LINK
Unfortunately, no. The "as DAL" in there will blow up without a using at the top of the page. The first approach I suggested should work without a using though.
ASP.NET PM
http://about.me/erikporter
Erik5388
Member
81 Points
84 Posts
Re: How to add WebMatrix default parameters?
Sep 03, 2010 02:26 PM|LINK
Hey... Interesting thing I stumbled on...
I created a Global.cs file and placed it in my app_code directory. I assigned my instances and variables as public static members...
using System; using System.MyDLL.Server.DAL; using System.Configuration; public static class Global { public static Exception ex = null; public static DAL dal = new DAL(); public static string ConnectionString = ConfigurationManager.ConnectionStrings["DB"].ConnectionString; public static void SetConnectionString() { dal.ConnectionString = ConnectionString; } }For the sake of keeping my connection string available on every page I called the SetConnectionString (above) function,
@{ Global.SetConnectionString(); }Becuase of the public static members in Global.cs I can call my instanced dal without creating a new instance of dal (this was done in Global.cs)
In conclusion,
By first created a public static class I can use it throughout my project...
zettersten.com
client side dev
canvas/html5/js/css
HumanCompile...
Member
511 Points
100 Posts
Microsoft
Re: How to add WebMatrix default parameters?
Sep 03, 2010 04:32 PM|LINK
I am almost completely sure that won't scale and you'll have issues when requests start coming in fast and each request is hitting the same variable. Your object should really be instantiated per request (stuffed in Context.Items or something that lives for the life of the request)...for now.
We're finishing up new simplified state management for the next release that will make what you're trying to do, much easier. Basically, you'll be able to say Page.dal = new DAL(); and set all your initial properties you need in _Init.cshtml, then in any web page you can access Page.dal. Simple. :)
ASP.NET PM
http://about.me/erikporter
Erik5388
Member
81 Points
84 Posts
Re: How to add WebMatrix default parameters?
Sep 06, 2010 12:07 AM|LINK
Darn, I thought I found something cool ><
What kind of issues will accur when requests come in faster?
I can revert back to the Context.Items as you mentioned earlier and thats fine...
However.... When does the next release come out?? heheh (= !?!?!?
zettersten.com
client side dev
canvas/html5/js/css