asp.net - 我是虚拟路径? [英] asp.net - Is my path virtual?
本文介绍了asp.net - 我是虚拟路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个内置的asp.net方法检查路径的虚拟性?
我已经能够做到这一点的唯一方法迄今与以下try块:
公共无效美孚(字符串路径){ 尝试
{
路径=使用Server.Mappath(路径);
}
赶上(HttpException){} //做的东西与路径
}
解决方案
将在的 Path.IsPathRooted 方法工作的?
您会导致code将是:
公共无效美孚(字符串路径)
{
如果(!Path.IsPathRooted(路径))
{
路径=使用Server.Mappath(路径);
} //做的东西与路径
}
Is there a built-in asp.net method for checking the "virtualness" of a path?
The only way I've been able to do it so far is with the following try block:
public void Foo(String path){
try
{
path = Server.MapPath(path);
}
catch(HttpException){}
// do stuff with path
}
解决方案
Would the Path.IsPathRooted method work?
You're resulting code would be:
public void Foo(String path)
{
if(!Path.IsPathRooted(path))
{
path = Server.MapPath(path);
}
// do stuff with path
}
这篇关于asp.net - 我是虚拟路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文