最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net application static静态变量用法
时间:2022-06-25 04:12:47 编辑:袖梨 来源:一聚教程网
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();
}
}
相关文章
- 塞尔达传说王国之泪汀空的头巾怎么获取 05-07
- 崩坏星穹铁道钟表小子美梦往事怎么玩 05-07
- 原神虹色大巡回第一天通关方法是什么 05-07
- 未定事件簿陆景和浮浪怎么样 05-07
- 崩坏星穹铁道流萤平民阵容怎么选择 05-07
- metamask钱包最新 05-07