2.0中的Global类代码发生了什么变化? [英] What happened to the Global class code behing in 2.0?

查看:84
本文介绍了2.0中的Global类代码发生了什么变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚开始转向ASP.NET 2.0并且遇到了Global.asax

代码文件的问题。


在1.1中我可以有一个代码global.asax文件的后台文件。对于Global类的共享变量,这允许

。注意:我将这些共享变量

用于在应用程序启动时设置的只读值。


看起来2.0不喜欢你在

全局类中使用共享变量。如何将我的1.1应用程序转换为2.0而没有

能够拥有这些共享变量?


为什么Microsoft会摆脱背后的global.asax代码?必须有一个

的理由和一个很好的转换方法(我希望)。

-

Pat B

BCC Software,Inc

AB ?? WE BELL + HOWELL COMPANY

Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This allow
for shared variables of the Global class. Note: I use these shared variables
for read only values that are set at application start.

It would appear the 2.0 doesn''t like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).
--
Pat B
BCC Software, Inc
A B??WE BELL + HOWELL COMPANY

推荐答案

这不再是默认,但你仍然可以使用它。


阅读这篇文章:
http://www.xerratus.com/2006/10/20/N...arateFile.aspx


您需要将所有global.asax代码放在global.asax.cs中的App_Code目录中


您必须在global.asax.cs的顶部包含它:


公共类Global:System.Web.HttpApplication


....并在global.asax中包含此指令:

<%@ Application Language =" C#"代码隐藏= QUOT; Global.asax.cs中"继承= QUOT;全球及QUOT; %>


与vb相同:

<%@ Application Language =" VB"代码隐藏= QUOT; Global.asax.vb"继承= QUOT;全球及QUOT; %>


从以下网址下载完整示例:

http://www.xerratus .com / ct.ashx?id = c ... iteExample.zip

Juan T. Llibre,asp.net MVP

asp .net faq: http://asp.net.do/faq/

foros de asp.net,en espa?ol: http:/ /asp.net.do/foros/

============================= =========

" PatB" < Pa ** @ community.nospamwrote in message news:45 *********************************** microsof t.com ...
It''s not the default any more, but you can still use it.

Read this article :
http://www.xerratus.com/2006/10/20/N...arateFile.aspx

You need to place all your global.asax code in global.asax.cs, in the App_Code directory

You must include this at the top of global.asax.cs :

public class Global : System.Web.HttpApplication

....and include this directive in global.asax :
<%@ Application Language="C#" CodeBehind="Global.asax.cs" Inherits="Global" %>

the same for vb :
<%@ Application Language="VB" CodeBehind="Global.asax.vb" Inherits="Global" %>

Download a complete example from :

http://www.xerratus.com/ct.ashx?id=c...iteExample.zip

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
======================================

"PatB" <Pa**@community.nospamwrote in message news:45**********************************@microsof t.com...

刚开始转向ASP.NET 2.0并遇到Global.asax

代码文件问题。


在1.1中,我可以为global.asax文件提供代码隐藏文件。对于Global类的共享变量,这允许

。注意:我将这些共享变量

用于在应用程序启动时设置的只读值。


看起来2.0不喜欢你在

全局类中使用共享变量。如何将我的1.1应用程序转换为2.0而没有

能够拥有这些共享变量?


为什么Microsoft会摆脱背后的global.asax代码?必须有一个

的原因和一个很好的转换方法(我希望)。


-

Pat B

BCC Software,Inc

AB?WE BELL + HOWELL COMPANY
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This allow
for shared variables of the Global class. Note: I use these shared variables
for read only values that are set at application start.

It would appear the 2.0 doesn''t like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).
--
Pat B
BCC Software, Inc
A B?WE BELL + HOWELL COMPANY



请不要假设任何事情并且总是发布您看到的确切行为

(运行时错误,编译时错误,确切错误消息)。

当然,如果我们尝试,它将起作用,因为我们不是在相同的条件下(我的

猜测会改变命名空间吗?)


我个人的偏好是使用特定的类(也是

配置类提供了一个API,它将公开存储在

Web应用程序配置类中的值,请参阅WebConfigurationManager)。


-

Patrice


" PatB" < Pa ** @community.nospamaécritdansle message de news:
45 ******************************* ***@microsoft.com ...
Please never assume anything and ALWAYS post the exact behavior you see
(runtime error, compile time error, exact error message).
Of course if we try, it will work as we are not in the same condition (my
guess would be a namespace change ?)

My personal preference would be to use a specific class (also the
configuration class provides an API that will expose values stored in your
web application config class, see WebConfigurationManager).

--
Patrice

"PatB" <Pa**@community.nospama écrit dans le message de news:
45**********************************@microsoft.com...

刚开始转向ASP.NET 2.0并遇到问题

Global.asax

代码文件。


在1.1中,我可以为global.asax文件提供代码隐藏文件。这个

允许全局类的共享变量获得
。注意:我将这些共享的

变量

用于在应用程序启动时设置的只读值。


它会出现2.0不希望你在

全局类中使用共享变量。如何将我的1.1应用程序转换为2.0而没有

能够拥有这些共享变量?


为什么Microsoft会摆脱背后的global.asax代码?必须有一个

的原因和一个很好的转换方法(我希望)。


-

Pat B

BCC Software,Inc

AB?WE BELL + HOWELL COMPANY
Just starting to move to ASP.NET 2.0 and having trouble with the
Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This
allow
for shared variables of the Global class. Note: I use these shared
variables
for read only values that are set at application start.

It would appear the 2.0 doesn''t like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).
--
Pat B
BCC Software, Inc
A B?WE BELL + HOWELL COMPANY



Juan,


我实现了解决方案,它似乎正在工作。


在我的1.1代码中,我可以通过
引用这些共享变量
Global.VariableName。在2.0代码中,似乎我需要引用

然后使用两个全局引用,如下所示:Global.Global.VariableName。


应该是这样的?有什么不对吗?这意味着转换

我的1.1。应用程序我将不得不做出很多改变来改变Global。

对Global.Global的引用。


有谁知道为什么微软的原因删除模型背后的代码

为global.asax?

-

Pat B

BCC软件,公司

AB ??我们BELL + HOWELL公司

" Juan T. Llibre"写道:
Juan,

I implemented the work-around and it appears to be working.

In my 1.1 code I can reference these shared variables by
Global.VariableName. In the 2.0 code it appears that I need to reference
then with two global references like this: Global.Global.VariableName.

Should it be like this? Is something wrong? This will mean when converting
my 1.1. apps I''ll have to make a lot of changes to change the Global.
reference to Global.Global.

Does anyone know the reasoning why Microsoft removed the code behind model
for the global.asax?
--
Pat B
BCC Software, Inc
A B??WE BELL + HOWELL COMPANY
"Juan T. Llibre" wrote:

它不再是默认值,但你仍然可以使用它。


阅读这篇文章:
http://www.xerratus.com /2006/10/20/N...arateFile.aspx

您需要将所有global.asax代码放在global.asax.cs中的App_Code中目录


你必须将它包含在global.asax.cs的顶部:


公共类Global:System.Web.HttpApplication


....并在global.asax中包含此指令:

<%@ Application Language =" C#"代码隐藏= QUOT; Global.asax.cs中"继承= QUOT;全球及QUOT; %>


与vb相同:

<%@ Application Language =" VB"代码隐藏= QUOT; Global.asax.vb"继承= QUOT;全球及QUOT; %>


从以下网址下载完整示例:

http://www.xerratus .com / ct.ashx?id = c ... iteExample.zip



Juan T. Llibre,asp.net MVP

asp.net faq: http://asp.net.do/faq/

foros de asp.net,en espa?±ol: http://asp.net.do/foros/

======================== ==============


" PatB" < Pa ** @ community.nospamwrote in message news:45 *********************************** microsof t.com ...
It''s not the default any more, but you can still use it.

Read this article :
http://www.xerratus.com/2006/10/20/N...arateFile.aspx

You need to place all your global.asax code in global.asax.cs, in the App_Code directory

You must include this at the top of global.asax.cs :

public class Global : System.Web.HttpApplication

....and include this directive in global.asax :
<%@ Application Language="C#" CodeBehind="Global.asax.cs" Inherits="Global" %>

the same for vb :
<%@ Application Language="VB" CodeBehind="Global.asax.vb" Inherits="Global" %>

Download a complete example from :

http://www.xerratus.com/ct.ashx?id=c...iteExample.zip

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?±ol : http://asp.net.do/foros/
======================================

"PatB" <Pa**@community.nospamwrote in message news:45**********************************@microsof t.com...

刚开始转向ASP.NET 2.0并遇到Global.asax

代码文件问题。


在1.1中,我可以为global.asax文件提供代码隐藏文件。对于Global类的共享变量,这允许

。注意:我将这些共享变量

用于在应用程序启动时设置的只读值。


看起来2.0不喜欢你在

全局类中使用共享变量。如何将我的1.1应用程序转换为2.0而没有

能够拥有这些共享变量?


为什么Microsoft会摆脱背后的global.asax代码?必须有一个

的理由和一个很好的转换方法(我希望)。

-

Pat B

BCC Software,Inc

AB ?? WE BELL + HOWELL COMPANY
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax
code file.

In 1.1 I could have a code behind file for the global.asax file. This allow
for shared variables of the Global class. Note: I use these shared variables
for read only values that are set at application start.

It would appear the 2.0 doesn''t like you to use shared variables in the
global class. How do I convert my 1.1 applications to 2.0 without the
ability to have these shared variables?

Why would Microsoft get rid of the global.asax code behind? There must a
reason and a good conversion method (I hope).
--
Pat B
BCC Software, Inc
A B??WE BELL + HOWELL COMPANY






这篇关于2.0中的Global类代码发生了什么变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆