1、命名空间和文件夹的名字可以不一样吗?答案是可以的。编译时可以通过的,你也可以设置命名空间的名字与文件夹的名字不一致;(面试问题)
2、类中的成员字段 int 类型,private int i; //每次初始化完毕后都是0 ;
3、地址栏每次请求。IncDemo.ashx 程序,都会将.ashx中的类重新new 一个新的对象!
4、一个坑儿:当复制一个.ashx文件的时候,需要,将副本文件名字改的同时,还要打开副本文件,将类名字改成与原文件不同名字。同时在资源管理器中打开,用记事本打开,将.ashx文件中的类名字,也改成不同于原文件的名字,并且和副本文件.ashx.cs中的类名字是一样的;~!!
代码验证:MemoryTest.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form action="MomeryTest.ashx" method="post">
<input type="text" name="number" value="{number}" />
<input type="submit" name="btn1" />
<!--这里可以用来控制一个层的手动增长-->
<input type="text" style=" width:{number}0px;border-color:blue;" />
</form>
</body>
</html>MemoryTest.ashx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Web1.Day3;
namespace Web1.Day4
{
/// <summary>
/// 实现点击数字自动增长的记忆功能!!!
/// </summary>
public class MomeryTest : IHttpHandler
{
//private int i;//该字段默认初始化时0;在这里只是做一下说明
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
//1、引入CommonHelper这个类的命名空间
//2、读取html模板页
string html = CommonHelper.ReadHtml("~/Day4/MomeryTest.html");
//3、查看请求的报文,如果请求的报文是第一次加载的页面,,
// 报文中是没有name="btn1"的,因为第一次加载的时候,你没有点击这个”提交“按钮
// 所以可以以这个特点进行数值的赋值的判断
if (string.IsNullOrEmpty(context.Request["btn1"]))
{
//4、页面刚加载的情况
//5、替换指定的字符串
html = html.Replace("{number}", "0");
//i = 0;
}
else
{
//i++;
int num=Convert.ToInt32( context.Request["number"]);
num++;
//i=num;
// html = html.Replace("{number}", i.ToString());
html = html.Replace("{number}", num.ToString());
}
context.Response.Write(html);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}