當前位置:
首頁 >
第 1 节: 1-文本自增演示HttpHandler不记忆状态
發布時間:2025/5/22
27
豆豆
生活随笔
收集整理的這篇文章主要介紹了
第 1 节: 1-文本自增演示HttpHandler不记忆状态
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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;}}} }?
轉載于:https://www.cnblogs.com/xcl461330197/articles/4546271.html
總結
以上是生活随笔為你收集整理的第 1 节: 1-文本自增演示HttpHandler不记忆状态的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一级大豆油商标可以加精炼油吗为什么?
- 下一篇: 康乐部在饭店的地位与任务是什么?