Reputation: 6829
I use Server.MapPath
to access some images on server. And I got the right path but can't open it.
The error I got is:
Not allowed to load local resource: d:/Project/MyProject/WebUI/Uploads/User_18234/leopard.jpg
I suppose that this will work on server. But I need it on localhost to test. Is there any solution for this?
...
userId = GetUserId();
string path = Server.MapPath("Uploads/User_" + userId + "/");
model.Name = path + model.Name + "_Original." + model.Extension;
...
Upvotes: 3
Views: 14909
Reputation: 29
You can try this
string url ="E:\braja" ;
var path = Path.Combine(@"" + url + "","_" + fileName);
it work for me
Upvotes: 0
Reputation: 1529
For me removing Server.MapPath worked.. I use tild ('~') sign with the url and it worked perfectly.
string path = "~/Uploads/User_" + userId + "/";
Upvotes: 2
Reputation: 2627
You can try this
string path = Server.MapPath("~/Uploads/User_" + userId + "/");
Map path need Virtual path so "~/" will surely fix it.
Upvotes: 2