久久国产亚洲日韩一本,欧美日韩专区国产精品,久久精品成人欧美大片,久久久久久久岛国免费AV,亚洲欧洲精品一区二区

新聞建站cms系統、政府cms系統定制開發

廣州網站建設公司-閱速公司

asp.net新聞發布系統、報紙數字報系統方案
/
http://www.ainiby.com/
廣州網站建設公司
您當前位置:首頁>ASP.NET MVC

ASP.NET MVC

何謂HttpContext上下文?

發布時間:2009/6/29 10:57:49  作者:  閱讀:1349  

廣告:

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

這是廣義上的上下文環境。aspx可以直接用Response,可以理解HttpContext獲取的上下文就是這個葉面上下文,用context.Response和直接用Response沒什么區別。但如果是業務邏輯.cs文件,就不是aspx環境了,是不能直接使用Response等操作的,需要先取得當前上下文環境,就要用HttpContext。

如何才能從業務類中訪問會話狀態值?
回答:很簡單!使用 HttpContext.Current 獲取 Context 對象,然后訪問 Context.Session。

HttpContext.Current

返回當前請求的 HttpContext 對象。如此我們就可以直接訪問Request、Response、Session、Application等對象,和Page中訪問等同。
我們無需再將Page用參數的方式傳遞到我們的類庫對象中。

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

HttpRuntime

為當前應用程序提供一組 ASP.NET 運行時服務。我們可以通過這個類獲得當前ASP.NET工程的一些信息。

HttpRuntime.AppDomainAppVirtualPath : 項目虛擬路徑
HttpRuntime.AppDomainAppPath : 項目物理路徑
HttpRuntime.BinDirectory : BIN目錄物理路徑
HttpRuntime.ClrInstallDirectory : CLR安裝路徑(可以用來獲取CLR版本號)

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

廣告:

相關文章
何謂HttpContext上下文?
cms新聞系統購買咨詢
掃描關注 廣州閱速軟件科技有限公司
掃描關注 廣州閱速科技
主站蜘蛛池模板: 茶陵县| 嘉定区| 松阳县| 洛浦县| 辽阳县| 衡阳市| 拉孜县| 黄石市| 隆德县| 阳原县| 高陵县| 志丹县| 辰溪县| 海原县| 中山市| 吴江市| 阳山县| 马鞍山市| 绥宁县| 扶绥县| 邵阳县| 广元市| 松潘县| 巴中市| 神农架林区| 红安县| 岗巴县| 竹溪县| 安塞县| 长寿区| 天长市| 宁德市| 衢州市| 怀远县| 繁昌县| 凤冈县| 昆明市| 满洲里市| 博野县| 屯留县| 阳信县|