Server.MapPath – Server operation is not available in this context

November 21, 2007

I have just tried to use Server.MapPath in a class file, which failed as the class file has no context as an HTTP application – Only the web form has this. The solution is to pass the HTTP application instance into the class, there by giving us a reference to the page as an application.


Private _HttpApplication

Public Sub New(ByRef httpApplication As System.Web.HttpApplication)
_HttpApplication = httpApplication
End Sub

Advertisements

3 Responses to “Server.MapPath – Server operation is not available in this context”

  1. virtualadrian said

    How about using ::

    System.Web.HttpContext.Current.Server.MapPath( … )

  2. Sabarinathan Arthanari said

    Hi,

    Please remember there is no context for some occasions

  3. john a. bailo said

    I ended up using an appSettings variable to define the path to avoid Server.MapPath.

    Worked just fine for defining a path to a file.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: