Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server.MapPath() wrong path on IIS

Tags:

asp.net

iis

I am trying to upload image to a folder called ~/Avatars/.

My project is located in VS2010 projects folder `C:/Projects/MyProject.

When i try to get physical path to Avatars folder by

Server.MapPath("/Avatars")

it always returns

C:\inetpub\wwwroot\Avatars 

instead of

C:\Projects\MyProject\Avatars.

It works fine when I run the project on VS2010 dev server.

Can anyone help me how to get actual path in IIS?

like image 264
nolan Avatar asked Jul 09 '11 14:07

nolan


1 Answers

Seems like you're deploying to IIS and that's the default folder for deployment. When you run locally, dev server runs off your local folder.

What you need is Server.MapPath("~/Avatars") or Server.MapPath("Avatars"). Also, make sure when you deploy to IIS, you're site is being deployed to C:\inetpub\wwwroot\My Project\.

like image 157
Mrchief Avatar answered Oct 14 '22 00:10

Mrchief