获取虚拟目录
⑴ 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()); 获取调用类的信息,可以从父类知道子类的情况