All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
.NET2.0App_Code文件夹的使用_[Asp.Net教程]

Writer: delv Article type: Programming skills(编程技巧) Time: 2014/1/24 9:02:01 Browse times: 307 Comment times: 0

.NET2.0App_Code文件夹的使用_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

.NET2.0App_Code文件夹的使用_[Asp.Net教程]

在.NET2.0中,出现了App_Code文件夹。主要用途就是允许将代码进行动态编译(运行时编译) ,而不是象以前的版本那样,如果想引用类文件,必须通过DLL引用(必须编译生成好)。

另外该文件夹还有一个用途就是,允许放置多种语言编写的类文件(需要将其它语言的类文件放到子文件夹中)。这无疑在代码的共享上,提供了非常大的便利。下面就做一演示。

首先创建一个Web站点项目(C#)。

接下来添加一个C#类文件(CustomeClass.cs)到App_Code文件夹中。再添加一个子文件夹(Subdirectory)。

在Subdirectory下添加一个VB类文件(CommonClass.vb)。程序结构如图:

代码如下:

(1)CodeFolder2_cs.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Response.Write(new part1().method1());
Response.Write(new Class1().GetMessage());

}
}

(2)CustomClass.cs:

public partial class part1
{
public part1()
{
//
// TOD 在此处添加构造函数逻辑
//
}
public string method1()
{
return "fhh";
}
}

(3)CustomClass.vb:

Public Class Class1
Public Function GetMessage() As String
Return "fhh"
End Function
End Class

(4)web.config代码:

<configuration>
<system.web>
<compilation>
<codeSubDirectories>
<add directoryName="Subdirectory"/>
codeSubDirectories>
compilation>
system.web>
configuration>
(5)运行效果:

要注意:此例的web.config文件和页面文件(.aspx)与App_Code文件夹要在同一个级别上。

来源:sdtsfhh的blog





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.