无法访问ASP.Net 2.0中的Global.asax方法 [英] No access to Global.asax methods in ASP.Net 2.0
问题描述
我使用VS2005 Beta 2创建了一个简单的Web应用程序。
基本上,我添加了一个Web窗体和一个Global.asax文件。
在我的Global.asax中,我创建了一个类似的方法:
public static void TestGlobal(){
抛出新的异常(Foobar);
}
然而,问题是我无法从
$ b获得对此方法的访问权限$ b表单类,即此代码失败:
protected void Page_Load(object sender,EventArgs e){
Global.TestGlobal(); // Intellisense声称没有类全局存在。
}
您可以在ASP.Net 1.1中这样写,但是如何访问方法,
枚举等?
Ronnie
I''ve created a simple web application using VS2005 Beta 2.
Basically, I''ve added a Web Form and a Global.asax file.
In my Global.asax, I create a method like:
public static void TestGlobal() {
throw new Exception("Foobar");
}
The problem, however, is that I cannot gain access to this method from the
form class, i.e., this code fails:
protected void Page_Load(object sender, EventArgs e) {
Global.TestGlobal(); // Intellisense claims no class Global exist.
}
You would write like this in ASP.Net 1.1, but how would you access methods,
enums, etc in Global.asax in ASP.Net 2.0?
Ronnie
推荐答案
如果代码'全部在ASAX中(而不是ASAX代码隐藏),请尝试:
Global_asax.TestGlobal();
-Brock
DevelopMentor
http:// staff.develop.com/ballen
If the code''s all in the ASAX (instead of a ASAX codebehind), try:
Global_asax.TestGlobal();
-Brock
DevelopMentor
http://staff.develop.com/ballen
我使用VS2005 Beta 2创建了一个简单的Web应用程序。
基本上,我是''我添加了一个Web窗体和一个Global.asax文件。
在我的Global.asax中,我创建了一个方法,如:
public static void TestGlobal(){
抛出新的异常(Foobar);
}然而,问题是我无法从表单类访问此方法,即,此代码失败:
protected void Page_Load(object sender,EventArgs e){
Global.TestGlobal(); // Intellisense声称没有类全局存在。
}
你会在ASP.Net 1.1中这样写,但是如何在ASP中访问Global.asax中的方法,枚举等。 Net 2.0?
Ronnie
I''ve created a simple web application using VS2005 Beta 2.
Basically, I''ve added a Web Form and a Global.asax file.
In my Global.asax, I create a method like:
public static void TestGlobal() {
throw new Exception("Foobar");
}
The problem, however, is that I cannot gain access to this method from
the form class, i.e., this code fails:
protected void Page_Load(object sender, EventArgs e) {
Global.TestGlobal(); // Intellisense claims no class Global exist.
}
You would write like this in ASP.Net 1.1, but how would you access
methods, enums, etc in Global.asax in ASP.Net 2.0?
Ronnie
Global_asax也不是有效的命名空间,因此不会工作。
Ronnie
Brock Allen写道:
Global_asax isn''t a valid namespace either, so that doesn''t work.
Ronnie
Brock Allen wrote:
如果代码'全部在ASAX(而不是ASAX代码隐藏)中,尝试:
Global_asax.TestGlobal();
-Brock
DevelopMentor
http://staff.develop.com/ballen
If the code''s all in the ASAX (instead of a ASAX codebehind), try:
Global_asax.TestGlobal();
-Brock
DevelopMentor
http://staff.develop.com/ballen
>
它不是命名空间,它是从global.asax生成的类的名称。
我刚刚在本地测试它它很实用。我想知道可能会有什么不同......
-Brock
DevelopMentor
http://staff.develop.com/ballen
It''s not a namespace, it''s the name of the class generated from the global.asax.
I just tested it locally and it was functional. I''m wondering what might
be different....
-Brock
DevelopMentor
http://staff.develop.com/ballen
Global_asax也不是有效的命名空间,所以这不起作用。
罗尼
布洛克艾伦写道:
Global_asax isn''t a valid namespace either, so that doesn''t work.
Ronnie
Brock Allen wrote:
如果代码'全部在ASAX中(而不是ASAX代码隐藏),请尝试:
Global_asax.TestGlobal();
-Brock > DevelopMentor
http://staff.develop.com/ballen
If the code''s all in the ASAX (instead of a ASAX codebehind), try:
Global_asax.TestGlobal();
-Brock
DevelopMentor
http://staff.develop.com/ballen
这篇关于无法访问ASP.Net 2.0中的Global.asax方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!