ASP.NET内置对象之Application对象

 更新时间:2008年09月24日 23:59:00   作者:  
Application对象是HttpApplicationState类的一个实例,它可以产生一个所有Web应用程序都可以存取的变量,这个变量的可以存取范围涵盖全部使用者,也就是说只要正在使用这个网页的程序都可以存取这个变量。
新建一个网站,包括两个网页,代码如下:
1、Index.aspx代码: 
复制代码 代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 300px; height: 100px">
<tr>
<td style="width: 100px">
用户名:</td>
<td style="width: 246px">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
密 &nbsp;&nbsp; 码:</td>
<td style="width: 246px">
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox></td>
</tr>
<tr>
<td style="text-align: center;" colspan="2">
<asp:Button ID="Button1" runat="server" Text="登录" OnClick="Button1_Click" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>

Index.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;
public partial class Index : System.Web.UI.Page
{
string strInfo;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Application["Info"] = TextBox1.Text;
strInfo = Application["Info"].ToString();
if (TextBox1.Text == "admin" && TextBox2.Text == "admin")
{
Session["name"] = TextBox1.Text;
Response.Redirect("Default.aspx?Info=" + strInfo + "");//地址栏的传值
}
}
}
2、Default.aspx代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 500px; height: 323px">
<tr>
<td colspan="2">
<asp:TextBox ID="TextBox2" runat="server" Height="314px" Width="497px" TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Width="390px"></asp:TextBox></td>
<td>
&nbsp;
<asp:Button ID="Button2" runat="server" Text="发送" OnClick="Button2_Click" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
Default.aspx.cs代码:
using System;
using System.Data;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["name"].ToString();
/*对象的增加
Application.Add("App1", "Value1");
Application.Add("App2", "Value2");
Application.Add("App3", "Value3");
Response.Write("Application对象的使用");
Response.Write("<br>");
for (int i = 0; i < Application.Count; i++)
{
Response.Write("变量名:" + Application.GetKey(i));
Response.Write(",值:" + Application[i] + "<p>");
Response.Write("<br>");
}*/
}
protected void Button2_Click(object sender, EventArgs e)
{
Application["content"] = TextBox1.Text;
TextBox2.Text = TextBox2.Text + "\n" + Label1.Text + "说:" + Application["content"].ToString();
}
}

相关文章

  • 为ASP.NET Core强类型配置对象添加验证的方法

    为ASP.NET Core强类型配置对象添加验证的方法

    这篇文章主要给大家介绍了关于如何为ASP.NET Core强类型配置对象添加验证的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2018-12-12
  • .NET 开源配置组件 AgileConfig的使用简介

    .NET 开源配置组件 AgileConfig的使用简介

    这篇文章主要介绍了.NET 开源配置组件 AgileConfig的使用简介,帮助大家更好的理解和学习使用.net技术,感兴趣的朋友可以了解下
    2021-05-05
  • .Net页面局部更新引发的思考

    .Net页面局部更新引发的思考

    这篇文章主要是由.Net页面局部更新引发的一系列思考,整理了实现局部更新的解决方案及改进方案,感兴趣的小伙伴们可以参考一下
    2016-06-06
  • .net开发中批量删除记录时实现全选功能的具体方法

    .net开发中批量删除记录时实现全选功能的具体方法

    这篇文章介绍了.net开发中批量删除记录时实现全选功能的具体方法,有需要的朋友可以参考一下
    2013-11-11
  • asp.net异步获取datatable并显示的实现方法

    asp.net异步获取datatable并显示的实现方法

    这篇文章主要介绍了asp.net异步获取datatable并显示的实现方法,结合实例形式分析了asp.net一步操作datatable的相关技巧,需要的朋友可以参考下
    2016-03-03
  • asp.net小孔子cms中的数据添加修改

    asp.net小孔子cms中的数据添加修改

    最近都在看小孔子cms的代码,其添加与修改数据十分方便,做下笔记,代码主要提取自小孔子cms,去掉了不用的函数并把相关代码写到一个文件中
    2008-08-08
  • ASP.NET Core设置Ocelot网关限流

    ASP.NET Core设置Ocelot网关限流

    这篇文章介绍了ASP.NET Core设置Ocelot网关限流的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-04-04
  • .NET之后台用户权限管理实现

    .NET之后台用户权限管理实现

    在功能性比较强大的后台管理网站处于各种角度考虑多有应用权限管理功能。以公司内部管理系统为例,管理员根据不同员工所在不同部门赋予其不同权限,或者根据上下级隶属关系实现“金字塔”管理。本文内容有不尽不实之处恳请指正。
    2013-02-02
  • .NET使用Hisql实现菜单管理(增删改查)

    .NET使用Hisql实现菜单管理(增删改查)

    这篇文章介绍了.NET使用Hisql实现菜单管理(增删改查)的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-07-07
  • ASP.NET MVC使用Boostrap实现产品展示、查询、排序、分页

    ASP.NET MVC使用Boostrap实现产品展示、查询、排序、分页

    这篇文章介绍了ASP.NET MVC使用Boostrap实现产品展示、查询、排序、分页的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-09-09

最新评论