+ Reply to Thread
Results 1 to 2 of 2

Thread: Server.MapPath in Global.asax

  1. #1
    Junior Member
    Join Date
    Jan 2012

    Server.MapPath in Global.asax

    I get an error in the log files : Server Operation is not available in this context , I have added some initialization code In Application_Start event in global.asax.cs This code is run in a spawned thread (created using new Thread()). The initialization code uses Server.MapPath to get the physical path of a file. The initialization is not critical since even if it does not succeed, it will not be a problem for me. My question is: Why am I getting the Server not available error?

  2. #2
    the Server object is referenced via HttpContext.Current i.e. relative to the current request. I suspect its not available from Application_Start since there is no request present at that point. Regardless it won't reliably be available from within separate thread because the threads run independently from each other, therefore any request may have started or finished before your thread tries to access it.

    Try using HostingEnvironment.MapPath() instead as that is a static method.

+ Reply to Thread

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts