當前位置:首頁 » 知網查重 » 獲取虛擬目錄

獲取虛擬目錄

發布時間: 2021-03-13 22:25:17

⑴ JS怎樣獲得網站的根目錄或虛擬目錄的根地址

浩宇 (胸懷猶如宇宙,浩瀚無窮)

⑵ 求一個asp.net 程序實例。獲取當前網站所有虛擬目錄的絕對路徑

這是我以前寫的一個上傳圖片的時候,裡面用到了獲取路徑的代碼,你看看對你有用不吧,如果對這個代碼有不懂的,可以追問,下面附上我的代碼:
protected void btnUp_Click(object sender, EventArgs e)
{
//1.驗證是否選擇文件
if (fuImg.HasFile)
{
//2.驗證文件類型是否符合要求
//獲取文件後綴(.***)
string strFileType = Path.GetExtension(fuImg.PostedFile.FileName).ToLower();//獲取文件後綴名,ToLower():轉化為小寫
//4.獲取上傳後的目錄//將虛擬路徑映射成物理目錄路徑
string strPath = Server.MapPath(ConfigurationManager.AppSettings["upPath"].ToString());
//獲取配置文件Web.config中appSettings中的imgType
string strType = ConfigurationManager.AppSettings["imgType"].ToString();
if (strType.IndexOf(strFileType) > -1)
{
//3.驗證文件大小
if (fuImg.PostedFile.ContentLength < 2048000)
{
DateTime dtNow = DateTime.Now;
//以年月日創建文件夾
strPath += dtNow.ToString("yyyy-MM-dd")+"\\";
try
{
//驗證指定目錄文件夾是否存在
if (!Directory.Exists(strPath))
{
//創建文件夾
Directory.CreateDirectory(strPath);
}
//文件重命名
string strNewName = dtNow.ToString("yyyyMMddhhmmssfff") + strFileType;
//保存(伺服器)
fuImg.SaveAs(strPath + strNewName);
Response.Write("文件上傳成功!");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
else
Response.Write("對不起,上傳文件不得超過2M!");
}
else
Response.Write("對不起,上傳文件類型不正確!");
}
else
Response.Write("對不起,請選擇上傳文件!");
}

⑶ ASP.Net如何取得當前虛擬目錄名稱

這個錯誤出現的原因經常是 你把網站的根目錄當成伺服器文件夾的子目錄了 ,導致webconfig在子目錄裡面,你應該把你網站下面的所有文件拷貝到伺服器目錄中,而不是你得網站目錄文件夾拷貝到伺服器目錄中。現在你得伺服器上的目錄應該是:伺服器的目錄/你網站的文件夾目錄/webconfig,改成 伺服器的目錄/webconfig

⑷ javascript 獲取虛擬目錄路徑

javascript是客戶端腳本,嚴格來講,是獲取不了虛擬目錄路徑的。不知道你的意思是不是要取路徑?取路徑的話,可以這樣:在 http://10.12.30.40/下面的文件里加上:<div id='text'></div>
<script>
function $(o){return document.getElementById(o)}
var url=' http://10.12.30.40/index.asp';
var arr=url.split('/');
url=url.replace(arr[arr.length-1],'sdf/');
$('text').innerHTML=url;
//如果你要跳轉,直接這樣寫
location.href=url
</script>

⑸ 如何獲取已存在的虛擬目錄數量及各目錄的名稱

public static string VirDirSchemaName = "IIsWebVirtualDir";

public string CreateVirtualDirectory(string nameDirectory, string realPath, string defaultPage)

{

string _serverName = "localhost";

DirectoryEntry _iisServer = new DirectoryEntry("IIS://" + _serverName + "/W3SVC/1");

DirectoryEntry folderRoot = _iisServer.Children.Find("ROOT", VirDirSchemaName);

if (folderRoot == null)

return "IIS 未正常安裝";

if (folderRoot.Children == null)

return "IIS 可能未啟動";

DirectoryEntry existPath = null;

try

{

existPath = folderRoot.Children.Find(nameDirectory, VirDirSchemaName);

}

catch (Exception e)

{}

if (existPath != null)

{

StringBuilder sb;

sb = new StringBuilder();

System.DirectoryServices.PropertyCollection props = existPath.Properties;

foreach (System.DirectoryServices.PropertyValueCollection valcol in existPath.Properties)

{

sb.Append(valcol.PropertyName);

sb.Append ( ":" );

sb.Append ( valcol.Value.ToString());

sb.Append ("\r");

}

string f = sb.ToString();

}

DirectoryEntry newVirDir = null;

try

{

newVirDir = folderRoot.Children.Add(nameDirectory, folderRoot.SchemaClassName);

}

catch (Exception e)

{

return "Sorry!Error when adding the virtual path. Return message is : " + e.Message;

}

try

{

newVirDir.Properties["Path"].Insert(0, realPath); // 虛擬目錄的絕對路徑

newVirDir.Properties["AuthFlags"][0] = 5; //1:anonymouse, 4:windows

newVirDir.Properties["AccessExecute"][0] = false; // 可執行文件。執行許可權下拉菜單中

newVirDir.Properties["AccessRead"][0] = true; // 讀取

newVirDir.Properties["AccessWrite"][0] = false; // 寫入

newVirDir.Properties["AccessScript"][0] = true; // 可執行腳本。執行許可權下拉菜單中

newVirDir.Properties["ContentIndexed"][0] = true; // 資源索引

newVirDir.Properties["DefaultDoc"][0] = defaultPage; // DefaultPage; // 默認頁面

newVirDir.Properties["AppFriendlyName"][0] = "友好的目錄名稱"; // 友好的顯示名稱

newVirDir.Properties["AppIsolated"][0] = 2; // 值0 表示應用程序在進程內運行,值1 表示進程外,值2 表示進程池

newVirDir.Properties["DontLog"][0] = true;

newVirDir.Properties["ScriptMaps"].Value = ScriptArray().ToArray();

newVirDir.Invoke("AppCreate", true); //q確保創建成功

newVirDir.CommitChanges();

folderRoot.CommitChanges();

_iisServer.CommitChanges();

return "Add success";

}

catch (Exception e)

{

return "Error message is : " + e.Message;

}

return "-----------";

}

將Asp.net框架的版本設為2.0,其實在虛擬目錄屬性添加一個屬性即可,newVirDir.Properties["ScriptMaps"].Value = ScriptArray().ToArray();

newVirDir.Properties["ScriptMaps"].Value 是將獲得一個object的數組。

做的時候,跟本不知道虛擬目錄到底有哪些屬性,可是項目經理提示一下,就猶醍醐灌頂,他說創建一個目錄,然後讀取。有時候解決問題原來可以這樣。

希望給大家帶來點收獲。

public ArrayList ScriptArray()
{
ArrayList list = new ArrayList();
string[] array={".ascx",".asmx",".aspx",".config"};
for (int i = 0; i < array.Length; i++)
{
list.Add(array[i] + @",c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
}
return list;
}

⑹ 如何獲取IIS虛擬目錄的絕對路徑

成千上萬
chéng qiān shàng wàn
【解釋】形容數量很多。

【出處】老舍《神拳》第二幕:「做假事騙得了幾個人,騙不了成千上萬的人。」

【結構】聯合式。

【用法】可用於人;也可用於其它。一般作定語、狀語。

【正音】成;不能讀作「cénɡ」。

【辨形】萬;不能寫作「方」。

【近義詞】千千萬萬、不計其數

【反義詞】寥寥無幾、寥寥可數

【辨析】~和「不計其數」都形容數量極多。但~數量尚可計算;「不計其數」多得數不過來;所以「不計其數」表示的數量多。

【例句】國慶節晚上;~的人前往廣場觀賞焰火。

⑺ asp.net 獲取虛擬目錄

你配置IIS的時候就已經將虛擬路徑定義好了,外部訪問網站的時候就是連接到你虛擬路徑下,所以只要有許可權訪問網站就可以啟動你的EXE文件。
建議你配置訪問許可權。

⑻ C#怎麼獲取IIS站點和虛擬目錄信息例子代碼

usingSystem;
usingSystem.DirectoryServices;
usingSystem.Collections.Generic;
usingSystem.Text;
namespaceConsoleApplication1
{
classProgram
{
staticvoidMain(string[]args)
{
DirectoryEntryrootEntry=newDirectoryEntry("IIS://localhost/w3svc");
intsiteID=1;

foreach(.Children)
{
if(entry.SchemaClassName.Equals("IIsWebServer",StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("Name:{0}",entry.Name);
Console.WriteLine("Path:{0}",IISWorker.GetWebsitePhysicalPath(entry));
Console.WriteLine("ServerBindings:{0}",entry.Properties["ServerBindings"].Value);
Console.WriteLine();
DirectoryEntryvirEntry=newDirectoryEntry(entry.Path+"/ROOT");
foreach(.Children)
{
if(entryVirtual.SchemaClassName.Equals("IIsWebVirtualDir",StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("SchemaClassName:{0}",entryVirtual.SchemaClassName);
Console.WriteLine("Name:{0}",entryVirtual.Name);
Console.WriteLine("Path:{0}",entryVirtual.Properties["Path"].Value);
Console.WriteLine();
}
}
intID=Convert.ToInt32(entry.Name);
if(ID>=siteID)
{
siteID=ID+1;
}
}
}
}
}
publicclassIISWorker
{
///<summary>
///得到網站的物理路徑
///</summary>
///<paramname="rootEntry">網站節點</param>
///<returns></returns>
(DirectoryEntryrootEntry)
{
stringphysicalPath="";
foreach(.Children)
{
if((childEntry.SchemaClassName=="IIsWebVirtualDir")&&(childEntry.Name.ToLower()=="root"))
{
if(childEntry.Properties["Path"].Value!=null)
{
physicalPath=childEntry.Properties["Path"].Value.ToString();
}
else
{
physicalPath="";
}
}
}
returnphysicalPath;
}
}
}

⑼ 如何得到運行程序的虛擬路徑

1.asp.net webform用「Request.PhysicalApplicationPath獲取站點所在虛擬目錄的物理路徑,最後包含「\」;

2.c# winform用
A:「Application.StartupPath」:獲取當前應用程序所在目錄的路徑,最後不包含「\」;
B:「Application.ExecutablePath 」:獲取當前應用程序文件的路徑,包含文件的名稱;
C:「AppDomain.CurrentDomain.BaseDirectory」:獲取當前應用程序所在目錄的路徑,最後包含「\」;
D:「System.Threading.Thread.GetDomain().BaseDirectory」:獲取當前應用程序所在目錄的路徑,最後包含「\」;
E:「Environment.CurrentDirectory」:獲取當前應用程序的路徑,最後不包含「\」;
F:「System.IO.Directory.GetCurrentDirectory」:獲取當前應用程序的路徑,最後不包含「\」;

3.c# windows service服務中用「AppDomain.CurrentDomain.BaseDirectory」或「System.Threading.Thread.GetDomain().BaseDirectory」;
用「Environment.CurrentDirectory」和「System.IO.Directory.GetCurrentDirectory」將得到「 system32」目錄的路徑;
如果要使用「Application.StartupPath」或「Application.ExecutablePath 」,需要手動添加對「System.Windows.Forms.dll 」的引用,並在程序開頭用「using System.Windows.Forms」聲明該引用;

4.在卸載程序獲取系統安裝的目錄:
System.Reflection.Assembly curPath = System.Reflection.Assembly.GetExecutingAssembly();
string path=curPath.Location;//得到安裝程序類SetupLibrary文件的路徑,獲取這個文件路徑所在的目錄即得到安裝程序的目錄;

System.Diagnostics.StackFrame f = new System.Diagnostics.StackFrame(1);
MethodBase mb = f.GetMethod();
System.Web.HttpContext.Current.Response.Write(mb.DeclaringType.ToString()); 獲取調用類的信息,可以從父類知道子類的情況

熱點內容
塗鴉論文 發布:2021-03-31 13:04:48 瀏覽:698
手機資料庫應用 發布:2021-03-31 13:04:28 瀏覽:353
版面217 發布:2021-03-31 13:04:18 瀏覽:587
知網不查的資源 發布:2021-03-31 13:03:43 瀏覽:713
基金贖回參考 發布:2021-03-31 13:02:08 瀏覽:489
懸疑故事範文 發布:2021-03-31 13:02:07 瀏覽:87
做簡單的自我介紹範文 發布:2021-03-31 13:01:48 瀏覽:537
戰略地圖參考 發布:2021-03-31 13:01:09 瀏覽:463
收支模板 發布:2021-03-31 13:00:43 瀏覽:17
電氣學術會議 發布:2021-03-31 13:00:32 瀏覽:731