Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server.MapPath does not exist in current context

Inside my MVC4 project I have the namespace

prj.MVC4.Controllers

where I'm using Server.MapPath(..) without problem and on

prj.MVC4.Models

Server.MapPath(...) does not exist on current context.

I'm aware that Server.MapPath resides in System.Web and both namespace and assembly are added into class with using System.Web and System.Web.dll is added to the prj.

on Ctrl + .. I'm getting Microsoft.SqlServer as suggested namespace to add.

How to fix this?

like image 523
panjo Avatar asked Oct 05 '13 08:10

panjo


2 Answers

Server is a property of the controller, to access it elsewhere while running a web application you can use

System.Web.HttpContext.Current.Server
like image 77
MichaC Avatar answered Oct 26 '22 20:10

MichaC


Server property is accessible from within controller. You can also find it in HttpContext.Current provided that your app is executed inside asp.net environment.

like image 28
Zbigniew Avatar answered Oct 26 '22 18:10

Zbigniew