无码国产精成人午夜视频不卡,久久久无码精品亚洲日韩蜜桃 ,国产亚洲欧美日韩在线一区 ,狠狠色丁香婷婷综合久久来来去

新聞建站cms系統(tǒng)、政府cms系統(tǒng)定制開發(fā)

廣州網(wǎng)站建設(shè)公司-閱速公司

asp.net新聞發(fā)布系統(tǒng)、報(bào)紙數(shù)字報(bào)系統(tǒng)方案
/
http://m.szzsmy888.com/
廣州網(wǎng)站建設(shè)公司
您當(dāng)前位置:首頁(yè)>ASP.NET MVC

ASP.NET MVC

何謂HttpContext上下文?

發(fā)布時(shí)間:2009/6/29 10:57:49  作者:  閱讀:1381  

廣告:

HttpContext上下文,即ASPX的環(huán)境, 從HttpContext可以取到各種ASPX的信息。(Application級(jí)數(shù)據(jù), Session級(jí)數(shù)據(jù),當(dāng)前的Request/Response, Url, 安全設(shè)置等等~) 其實(shí)可以把它理解成 一個(gè)環(huán)境。

這是廣義上的上下文環(huán)境。aspx可以直接用Response,可以理解HttpContext獲取的上下文就是這個(gè)葉面上下文,用context.Response和直接用Response沒(méi)什么區(qū)別。但如果是業(yè)務(wù)邏輯.cs文件,就不是aspx環(huán)境了,是不能直接使用Response等操作的,需要先取得當(dāng)前上下文環(huán)境,就要用HttpContext。

如何才能從業(yè)務(wù)類中訪問(wèn)會(huì)話狀態(tài)值?
回答:很簡(jiǎn)單!使用 HttpContext.Current 獲取 Context 對(duì)象,然后訪問(wèn) Context.Session。

HttpContext.Current

返回當(dāng)前請(qǐng)求的 HttpContext 對(duì)象。如此我們就可以直接訪問(wèn)Request、Response、Session、Application等對(duì)象,和Page中訪問(wèn)等同。
我們無(wú)需再將Page用參數(shù)的方式傳遞到我們的類庫(kù)對(duì)象中。

HttpContext.Current.Session["name"] = "豬八戒";
string name = HttpContext.Current.Request.Param["name"];
HttpContext.Current.Response.Write("豬八戒好吃懶做!");

HttpRuntime

為當(dāng)前應(yīng)用程序提供一組 ASP.NET 運(yùn)行時(shí)服務(wù)。我們可以通過(guò)這個(gè)類獲得當(dāng)前ASP.NET工程的一些信息。

HttpRuntime.AppDomainAppVirtualPath : 項(xiàng)目虛擬路徑
HttpRuntime.AppDomainAppPath : 項(xiàng)目物理路徑
HttpRuntime.BinDirectory : BIN目錄物理路徑
HttpRuntime.ClrInstallDirectory : CLR安裝路徑(可以用來(lái)獲取CLR版本號(hào))

Response.Write(string.Format("AppDomainAppId: {0}<br>", HttpRuntime.AppDomainAppId));
Response.Write(string.Format("AppDomainAppPath: {0}<br>", HttpRuntime.AppDomainAppPath));
Response.Write(string.Format("AppDomainAppVirtualPath: {0}<br>", HttpRuntime.AppDomainAppVirtualPath));
Response.Write(string.Format("AppDomainId: {0}<br>", HttpRuntime.AppDomainId));
Response.Write(string.Format("AspInstallDirectory: {0}<br>", HttpRuntime.AspInstallDirectory));
Response.Write(string.Format("BinDirectory: {0}<br>", HttpRuntime.BinDirectory));
Response.Write(string.Format("ClrInstallDirectory: {0}<br>", HttpRuntime.ClrInstallDirectory));
Response.Write(string.Format("CodegenDir: {0}<br>", HttpRuntime.CodegenDir));
Response.Write(string.Format("IsOnUNCShare: {0}<br>", HttpRuntime.IsOnUNCShare.ToString()));
Response.Write(string.Format("MachineConfigurationDirectory: {0}<br>", HttpRuntime.MachineConfigurationDirectory));

輸出:
AppDomainAppId: /LM/W3SVC/1/Root/Learn.Test.Web
AppDomainAppPath: D:\System\My Documents\Visual Studio Projects\Learn.Test\Learn.Test.Web\
AppDomainAppVirtualPath: /Learn.Test.Web
AppDomainId: /LM/W3SVC/1/Root/Learn.Test.Web-9-127652564154400560
AspInstallDirectory: C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
BinDirectory: D:\System\My Documents\Visual Studio Projects\Learn.Test\Learn.Test.Web\bin\
ClrInstallDirectory: c:\windows\microsoft.net\framework\v1.1.4322
CodegenDir: C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\learn.test.web\41680132\7c880883
IsOnUNCShare: False
MachineConfigurationDirectory: c:\windows\microsoft.net\framework\v1.1.4322\Config

廣告:

相關(guān)文章
何謂HttpContext上下文?
cms新聞系統(tǒng)購(gòu)買咨詢
掃描關(guān)注 廣州閱速軟件科技有限公司
掃描關(guān)注 廣州閱速科技