佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 798|回复: 14

ASP.NET 2.0 和 ASP.NET 1.1

[复制链接]
发表于 23-2-2006 01:09 PM | 显示全部楼层 |阅读模式

小章鱼是 ASP.NET 新手
想请教
在 ASP.NET 2.0 环境里,可以建立 App_Code 的文件夹,然后把所有的 class 文件放到里边去
#myTestClass.cs#
public class myTestClass{
        public myTestClass() {
        }
}
ASP.NET 2.0 就会自动载入,以后在任何页面都可以使用 myTestClass
在 ASP.NET 1.1 要如何实现?
回复

使用道具 举报


ADVERTISEMENT

发表于 23-2-2006 10:24 PM | 显示全部楼层
ASP.NET 1.1 和 ASP.NET 2.0 的 syntax 是一样的... 没有分别.
回复

使用道具 举报

 楼主| 发表于 23-2-2006 10:28 PM | 显示全部楼层

可是在 ASP.NET 1.1 的环境里 App_Code 里的 class 并没有载入。

goatstudio 能不能给些例子?
回复

使用道具 举报

发表于 23-2-2006 10:36 PM | 显示全部楼层
原帖由 sson 于 23-2-2006 10:28 PM 发表

可是在 ASP.NET 1.1 的环境里 App_Code 里的 class 并没有载入。

goatstudio 能不能给些 ...


呵... 不太明白你讲什么呢... 因为我不太了解你说的 App_Code 是指什么...

我说的 syntax 一样是写法一样, 因为都是建立在物件导向的基础, 所以 namespace, class, extends, implements 等的写法还是一样.

ASP.NET 2.0 是加强了一些 class, 例如支持 Serial Port 的 class (我暂时唯一知道的... ), 有一些 class 的 method 也有可能 depreciated 了.
回复

使用道具 举报

 楼主| 发表于 23-2-2006 10:44 PM | 显示全部楼层

ASP.NET 2.0 里的 App_Code 文件夹是存放 custom classes 的
也就是说,可以把很多 class/namespace 分开在不同的文件

放入 App_Code 文件夹后,就可以在任何其他的 aspx 页面(不必做连接)直接使用其 class/namespace
感觉就像编 standalone app,

抱歉,小章鱼也说不清楚,对 ASP.NET 的了解是在有限。
回复

使用道具 举报

发表于 23-2-2006 10:55 PM | 显示全部楼层
不一定要放在 App_Code 的文件夹里, 任何一个都行, 只要 IIS 看得到就行.
我从就没制作 App_Code 文件夹.

基本上, 建立了一个 class, 你在任何一个 namespace 都可以用到.
假设你的 Project 的 dll 是 MyProject,
然后你的 namespace 是 MyNamespace1, 你在里面制作了一个 Class_1.
再然后你在另一个 namespace 里 MyNamespace2, 需要用到 Class_1, 那么你只需要这样写就可以了:

import MyProject.MyNamespace1;

好好运用 namespace 来整理你的 class, 也好好运用 public, private, protected 和 internal 把该隐藏的 code 都隐藏起来.
回复

使用道具 举报

Follow Us
 楼主| 发表于 23-2-2006 11:24 PM | 显示全部楼层

越讲越糊涂了……

ASP.NET 有 DLL 的?
回复

使用道具 举报

发表于 24-2-2006 02:31 PM | 显示全部楼层
是的,ASP.NET是有用DLL的。在你的project的folder里,有一个bin folder,DLL就是放在那里的。

ASP.NET2.0 和 ASP1.1的分别,可以参考这里
http://msdn.microsoft.com/asp.ne ... /html/Internals.asp

goatstudio 说的对,你的class是任何页面都可以使用,只要你reference 到它。所以就要用import来refer任何namaspace.
import MyProject.MyNamespace1;

你可以create any folder to organize your class,this is for user view only, but you need to use namespace to organize your class for the reference by other class.
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 26-2-2006 06:49 PM | 显示全部楼层

假设目前的架构是酱的
-root
   test.aspx
   /myclass
      class001.cs

在 class001.cs 里的代码是酱的
public class myTestClass{
        public myTestClass() {
        }
}


那么在 test.aspx 里要怎样才能使用 myTestClass ?
要怎样建立连接 class001.cs 的 reference ?

可以用 VS.Net 2005 来开发 ASP.NET 1.1 的作业吗?

目前用 VS.Net 2005 的作业都没有 /bin 文件夹的……
回复

使用道具 举报

发表于 26-2-2006 08:45 PM | 显示全部楼层
首先,你的class要放进一个namespace里

namespace MyNamespace1
{
  public class myTestClass{
        public myTestClass() {
        }
}
}

Case 1:
-root
   test.aspx
   /myclass
      class001.cs
      class002.cs

在 class002.cs 里的代码是酱的
namespace MyNamespace1
{
  public class myTestClass2{
        public myTestClass2() {
        }
}
}

如果你要refer myTestClass,只需

myTestClass myTestClassObj = new myTestClass();

不许要
import MyNamespace1;
以为两个class 是在同一个namespace


Case 2:
-root
   test.aspx
   /myclass
      class001.cs
      class002.cs
  test2.aspx
  /myclass2
   class003.cs

 
在 class003.cs 里的代码是酱的
namespace MyNamespace2
{
  public class myTestClass3{
        public myTestClass3() {
        }
}
}

如果你要refer myTestClass,

myTestClass myTestClassObj = new myTestClass();

需要
import MyNamespace1;
以为两个class 是在不同一个namespace

希望你可以明白,这就是namespace 的用处
回复

使用道具 举报

发表于 26-2-2006 08:51 PM | 显示全部楼层
[quote]原帖由 sson 于 26-2-2006 06:49 PM 发表


可以用 VS.Net 2005 来开发 ASP.NET 1.1 的作业吗?

目前用 VS.Net 2005 的作业都没有 /bin 文件夹的……

quote]

里论上是可以的,因为ASP2.0是backward compatible with ASP1.1的。

VS.Net 2005 没有/bin folder? 不清楚,还是用着VS.Net 2003

可能是你的compilation models的setting 不一样。

Normal (ASP.NET 1.x)—In a normal ASP.NET Web application, the code-behind files were compiled into an assembly and stored in the /bin directory. The Web pages (ASPX) were compiled on demand. This model worked well for most Web sites. However, the compilation process made the first request of any ASP.NET page slower than subsequent requests. ASP.NET 2.0 continues to support this model of compilation.

[ 本帖最后由 石破天金 于 26-2-2006 08:54 PM 编辑 ]
回复

使用道具 举报

 楼主| 发表于 26-2-2006 09:17 PM | 显示全部楼层

小章鱼知道 namespace 的用法

你的意思是说在 test.aspx 里要使用 myTestClass 是不需要做 referance 的?
小章鱼的 test.aspx 是没有用 code-behide 方式的
是用 inline-code <script> block 的


小章鱼目前的方式和你的讲解应该是一样的
但服务器却报错,详细错什么就不知道了,因为服务器的设定是不回传详细的错误讯息的。

小章鱼的代码只是一个壳,所以是不可能错的
依小章鱼的猜想,应该就是因为那些 .cs 文件并没有被执行。




小章鱼的意思就是 VS.NET 2005 可不可以设定为 ASP.NET 的 compilation
回复

使用道具 举报

发表于 27-2-2006 02:28 AM | 显示全部楼层
原帖由 sson 于 26-2-2006 09:17 PM 发表

小章鱼知道 namespace 的用法

你的意思是说在 test.aspx 里要使用 myTestClass 是不需要做 referance 的?


你没用 code-behind, 但你还需要做 reference.
你得在 aspx 最上端, 过了以下这段, 我用 C#:

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1"   Debug="true" %>

你得 import namespace, 如果你的 namespace 是 myclass:
<%@ Import Namespace="myclass" %>


你是可以显示详细的错误讯息, 你可以在 web.config 里的 <system.web> 里放 <customErrors mode="Off" />. 你用的是 visual studio, 可以用 step over 来 debug.
回复

使用道具 举报

 楼主| 发表于 28-2-2006 05:29 PM | 显示全部楼层

又有东西做了,学习又要暂时搁一旁了

goatstudio 小章鱼有个疑惑,
<%@ Import Namespace="myclass" %>
ASP.NET 怎么知道小章鱼的 myclass 编在那个文件里?


至于错误讯息,在服务器上,一有错误就自动转到 custom page 去了……
又没有办法在本机上测试,因为用的是 VS.NET 2005
回复

使用道具 举报

发表于 28-2-2006 09:11 PM | 显示全部楼层
原帖由 sson 于 28-2-2006 05:29 PM 发表

又有东西做了,学习又要暂时搁一旁了

goatstudio 小章鱼有个疑惑,
<%@ Import N ...


我不太清楚 VS.NET 2005 是怎么做, 但我相信和 2003 相去不远.
每一次我做完了更改, 需要测试... 我就 compile 它, 然后得出 dll.

至于你的做法, 我就不太清楚, 但是只要你制作了 class , compile 了,
那么各 namespace 里的结构自动会一清二楚了.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 21-9-2024 10:57 PM , Processed in 0.114833 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表