ApplicationPath vs“〜”,哪个更好找到应用程序路径?

时间:2021-08-07 16:06:15

I needed to get the Base-/Application-Path of my ASP.NET-MVC-5-Application.

我需要获得我的ASP.NET-MVC-5-Application的Base- / Application-Path。

I found two opportunities to get it and wonder what is the better choice:

我找到了两个获得它的机会,并想知道什么是更好的选择:

UrlHelper.Content("~") 

or

UrlHelper.RequestContext.HttpRequest.Request.ApplicationPath

1 个解决方案

#1


0  

Use this, i think this is better

使用这个,我认为这更好

Server.MapPath("~/YourFolder/");

here "~" represents your rootfolder

这里“〜”代表你的rootfolder

ie. If you want to get "pic1.gif" file from "Contents" folder

即。如果你想从“Contents”文件夹中获取“pic1.gif”文件

simply use

string _path = Server.MapPath("~/Contents/");
string _myFile = "pic1.gif";
string _fullPath = _path + _myFile;

#1


0  

Use this, i think this is better

使用这个,我认为这更好

Server.MapPath("~/YourFolder/");

here "~" represents your rootfolder

这里“〜”代表你的rootfolder

ie. If you want to get "pic1.gif" file from "Contents" folder

即。如果你想从“Contents”文件夹中获取“pic1.gif”文件

simply use

string _path = Server.MapPath("~/Contents/");
string _myFile = "pic1.gif";
string _fullPath = _path + _myFile;