asp.net - Is my path virtual?

让人想犯罪 __ 提交于 2019-12-24 11:35:50

问题


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
}

回答1:


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
}



回答2:


Here is everything you need to know about ASP.Net paths: Rick Strahl's post "Making Sense of ASP.Net Pahts"



来源:https://stackoverflow.com/questions/1308723/asp-net-is-my-path-virtual

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!