五月天亚洲色图_亚洲精品少妇_亚洲熟妇无码av另类本色_自拍高清综合中文_成年女人wwxx免费_国产高清视频在线观看三区_下载香蕉视频app_芒果视频下载_日韩AV综合无码中文一区_国产日产精品久久

在線幫助 ICP備案 合作機(jī)構(gòu) 我要訂制
 
 7×24客服熱線:13663712063
您的位置:首頁  技術(shù)支持 C#取得Web程序和非Web程序的根目錄的N種取法
       越辰家政管理軟件
       越辰空調(diào)售后管理軟件
       越辰圖書銷售管理軟件
       越辰物業(yè)管理軟件
       越辰茶樓管理軟件
       越辰幼兒園管理軟件
       越辰餐飲管理軟件
       越辰病歷管理系統(tǒng)
       越辰洗浴管理軟件
       越辰住院管理系統(tǒng)
       越辰超市管理系統(tǒng)
  

C#取得Web程序和非Web程序的根目錄的N種取法

來源:yocin  時(shí)間:2010-12-10 20:42:48  欄目:技術(shù)支持  點(diǎn)擊率:1841

(越辰家政軟件部整理)幾種方法如下:
非Web程序

1.AppDomain.CurrentDomain.BaseDirectory //瀏覽器安裝路徑

2.Environment.CurrentDirectory


3.HttpRuntime.BinDirectory

The path to the current application's/bin directory.


Web程序

HttpCurrent.Context.Server.Mappath();

---------------------------------------------------------------

HttpContext.Current

返回當(dāng)前請(qǐng)求的 HttpContext 對(duì)象。如此我們就可以直接訪問Request、Response、Session、Application等對(duì)象,和Page中訪問等同。
我們無需再將Page用參數(shù)的方式傳遞到我們的類庫對(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ù)。我們可以通過這個(gè)類獲得當(dāng)前ASP.NET工程的一些信息。

HttpRuntime.AppDomainAppVirtualPath : 項(xiàng)目虛擬路徑
HttpRuntime.AppDomainAppPath : 項(xiàng)目物理路徑
HttpRuntime.BinDirectory : BIN目錄物理路徑
HttpRuntime.ClrInstallDirectory : CLR安裝路徑(可以用來獲取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

 

HostingEnvironment

string siteName = HostingEnvironment.SiteName;
string appPath = HostingEnvironment.ApplicationVirtualPath;
string phyPath = HostingEnvironment.ApplicationPhysicalPath;
string adminPath = HostingEnvironment.MapPath("~/Admin");

ApplicationManager.GetApplicationManager().ShutdownApplication(HostingEnvironment.ApplicationID); 


靈活運(yùn)用技巧:

當(dāng)使用非WEB程序或使用異步調(diào)用時(shí),想要取得根目錄下的某目錄可以使用如下代碼:

HttpRuntime.BinDirectory + "../目錄名";

Copyright ◎2008-2018鄭州越辰科技有限公司 版權(quán)所有 網(wǎng)站地圖
地址:中國·河南鄭州市文化路交北環(huán)路北晨e時(shí)代B座505室 
電話:0371-63399049 13663712063 備案號(hào):豫ICP備19031456號(hào)
我們專注于 軟件開發(fā)| 網(wǎng)站制作  返回歡迎頁 
  
點(diǎn)擊這里給我發(fā)消息 越辰業(yè)務(wù)
點(diǎn)擊這里給我發(fā)消息 越辰業(yè)務(wù)
點(diǎn)擊這里給我發(fā)消息 越辰代理
點(diǎn)擊這里給我發(fā)消息 越辰技術(shù)
 ,頁面執(zhí)行時(shí)間:15.625毫秒        
up close

返回頂部

越辰科技微信
微信掃一掃