最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net application static静态变量用法
时间:2011-05-30 编辑:简简单单 来源:一聚教程网
asp教程.net application static静态变量用法
File: Global.asax
<%@ Application Language="C#" ClassName="Global" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections.Generic" %>
private static string[] fileList;
public static string[] FileList
{
get
{
if (fileList == null)
{
fileList = Directory.GetFiles(HttpContext.Current.Request.PhysicalApplicationPath);
}
return fileList;
}
}private static Dictionary
metadata = new Dictionary ();
public void AddMetadata(string key, string value)
{
lock (metadata)
{
metadata[key] = value;
}
}
public string GetMetadata(string key)
{
lock (metadata)
{
return metadata[key];
}
}
File: Default.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="StaticApplicationVariables" %>
Untitled Page
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using ASP;public partial class StaticApplicationVariables : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder builder = new StringBuilder();
foreach (string file in Global.FileList)
{
builder.Append(file + "
");
}
lblInfo.Text = builder.ToString();
}
}
相关文章
- asp.net static静态变量 05-29
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10