读书人

如何给asp.net创建全局变量

发布时间: 2012-01-01 23:10:55 作者: rapoo

怎么给asp.net创建全局变量?
在global.asax中建立的其他文件取不出来,是我搞错了吗?

public static String aStr;
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
EntryFilePath = Server.MapPath( "abc ");
}
比如default.aspx.cs和App_Code/class.cs中就取不到aStr的值
哪里错了吗?
该如何建立全局变量?

[解决办法]
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application[ "EntryFilePath "] = Server.MapPath( "abc ");
}

[解决办法]
可以在Application_Start中使用Application变量:

string astr = "abc ";
Application[ "ASTR "] = astr;

-------------------------------------------
在default.aspx.cs种如下方法取出:

string bstr = Application[ "ASTR "].ToString();

//对Application变量取出事要做类型转换

读书人网 >asp.net

热点推荐