Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Server.MapPath() from global.asax?

People also ask

What is the use of server MapPath in asp net?

The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.


You could try System.Web.Hosting.HostingEnvironment.MapPath().

No HttpContext required.


Use AppDomain.CurrentDomain.BaseDirectory because Context might return null !!


When in Global.asax, use the context object:

context.Server.mappath()

Context lets you access also the session collection, the request object, the response object. Very useful when you want to log errors, for example