Hi all,
I am very new to ASP.NET and C# so please excuse my ignorance if this
is a FAQ (I have looked but couldn't find anything).
I have several functions that I use on nearly all my aspx pages.
for example:
void Include(string filename){
//dynamically build path of file that is to be included
StringBuilder b = new StringBuilder("/");
b.Append(Application["AppRoot"]);
b.Append("system/include/");
b.Append(filename);
//"#include" the file using Server.Execute rather than a normal
#include command
Server.Execute(b.ToString());
}
Rather than have this code existing in _every_ aspx page I was hoping
to put it into global.asax and reference it as normal from any aspx
page. But as you probably would have guessed by now - it didn't work.
When I remove the function from the aspx pages and place it into
global.asax I get the following error (from page "home.aspx"): Compiler
Error Message: CS0103: The name 'Include' does not exist in the class or
namespace 'ASP.home_aspx'.
I have copied the contents of global.asax (as it currently exists)
below. My code works fine when it is like this. When I move the Include
function into the global.asax (immediately after void Application_Start)
it all goes pear-shaped...
<script language="cs" runat="server">
void Application_Start(Object sender, EventArgs e) {
//get RootPath from web.config using AppRoot as key
string applicationRootPath
ConfigurationSettings.AppSettings["AppRoot"];
Application["AppRoot"] = applicationRootPath;
}
</script>
Can anyone tell me how to place functions into the global.asax files
and use them from any page? I would hate to have to copy any changes to
these quite simple functions into every page when I made adjustments to
them.
Cheers,
JasonP.
**********************************************************************
WARNING
This email message and any attached files may contain information
that is confidential and subject of legal privilege intended only for
use by the individual or entity to whom they are addressed. If you
are not the intended recipient or the person responsible for
delivering the message to the intended recipient be advised that you
have received this message in error and that any use, copying,
circulation, forwarding, printing or publication of this message or
attached files is strictly forbidden, as is the disclosure of the
information contained therein. If you have received this message in
error, please notify the sender immediately and delete it from your
InBox.
AFP Web site: http://www.afp.gov.au
**********************************************************************