ASP.NET的IIS5與IIS6.0
自從有了html與http,就有了瀏覽器與Web服務(wù)器,并有了Web應(yīng)用,最初的交互模式是這樣的:
該模式很好地運(yùn)行了很多年。然而,隨著計(jì)算機(jī)應(yīng)用的發(fā)展,人們越來越不滿足于只有靜態(tài)內(nèi)容的頁面,而由某種機(jī)制動態(tài)產(chǎn)生html等代碼的需求越來越迫切,于是,很多技術(shù)就應(yīng)運(yùn)而生,ASP.NET就是這樣一種技術(shù)。從本質(zhì)上講,ASP.NET就是一種服務(wù)器端動態(tài)產(chǎn)生html、css、javascript等瀏覽器認(rèn)識的代碼的技術(shù)。ASP.NET的交互模式如下:
由該圖可知,ASP.NET必須解決兩大問題,一是如何與Web服務(wù)器(一般就是指IIS)進(jìn)行交互,二是如何根據(jù)不同請求產(chǎn)生不同的html等代碼。
***個(gè)問題,根據(jù)IIS版本(5,6.0,7.0)的不同,ASP.NET具有不同的進(jìn)程模式與不同的交互模式,該問題不是本篇要講述的。一般來說,大家不必關(guān)心該問題,而且要了解該問題,又必須清楚IIS各個(gè)版本的模型,而各個(gè)版本又各有各的不同,因此,我基本不準(zhǔn)備講述這個(gè)問題,大家有興趣的話,可以自行搜索相關(guān)資料。
我們來討論第二個(gè)問題,這里首先要說明的是,因?yàn)镮IS7.0進(jìn)程模式的變化比較大,我也沒去了解IIS7.0的模型,因此,以下講述及以后講述將只針對IIS5與IIS6.0.我們有理由認(rèn)為,針對IIS5與IIS6.0的講述一般同樣適用于IIS7.0.
先且按下該問題不表,我們來看一段請求玉帝把大象放到冰箱里的代碼(為什么不是上帝?因?yàn)槲抑腥A不歸上帝管),請大家先跟著我的思路來,別急,別急。
- usingSystem;
- namespaceConsoleApplication3
- {
- classProgram
- {
- staticvoidMain(string[]args)
- {
- Emperoremperor=newEmperor();
- while(true)
- {
- Console.WriteLine("首先給玉帝準(zhǔn)備好大象和冰箱。");
- Console.WriteLine("輸入大象的名字:");
- stringelephantName=Console.ReadLine();
- Console.WriteLine("輸入大象的體重:");
- intintelephantWeight=int.Parse(Console.ReadLine());
- Console.WriteLine("輸入冰箱的名字:");
- stringrefrigeratorName=Console.ReadLine();
- Elephantelephant=newElephant()
- {
- Name=elephantName,
- Weight=elephantWeight
- };
- Refrigeratorrefrigerator=newRefrigerator()
- {
- Name=refrigeratorName
- };
- Contextcontext=newContext()
- {
- Elephant=elephant,
- Refrigerator=refrigerator
- };
- emperor.ProcessRequest(context);
- Console.WriteLine("是否要玉帝繼續(xù)把大象關(guān)進(jìn)冰箱里?");
- stringanswer=Console.ReadLine();
- if(answer=="n")
- break;
- }
- }
- }
- classEmperor
- {
- publicvoidProcessRequest(Contextcontext)
- {
- Elephantelephant=context.Elephant;
- Refrigeratorrefrigerator=context.Refrigerator;
- //***步,打開冰箱門
- refrigerator.IsOpen=true;
- Console.WriteLine(string.Format("玉帝打開了{(lán)0}的冰箱門。",
refrigerator.Name));- //第二步,把大象放進(jìn)去
- refrigerator.Content=elephant;
- Console.WriteLine(string.Format("玉帝把大象{0}放到冰箱{1}里了。",
elephant.Name,refrigerator.Name));- //第三步,關(guān)上冰箱門
- refrigerator.IsOpen=false;
- Console.WriteLine(string.Format("玉帝關(guān)上了{(lán)0}的冰箱門。",
refrigerator.Name));- }
- }
- classElephant
- {
- publicstringName{get;set;}
- publicintWeight{get;set;}
- }
- classRefrigerator
- {
- publicstringName{get;set;}
- publicboolIsOpen{get;set;}
- privateobjectm_Content;
- publicobjectContent
- {
- get{returnthis.m_Content;}
- set
- {
- if(!this.IsOpen)
- thrownewInvalidOperationException("冰箱門未打開,無法放進(jìn)東西。");
- if(this.m_Content!=null)
- thrownewInvalidOperationException("冰箱內(nèi)有東西,無法放進(jìn)新的東西。");
- this.m_Content=value;
- }
- }
- }
- classContext
- {
- publicElephantElephant{get;set;}
- publicRefrigeratorRefrigerator{get;set;}
- }
- }
【編輯推薦】