I have a SignalR hub. When the client disconnects, I want to perform a file operation.
To do that, I need to access the Server.MapPath
.
However, as my Hub class is not an .aspx or a Web Service, there is no HttpContext
nor request.
I thought of delegating the IO work to the HTTP request handler, but I can not create a WebRequest with a relative URI and I need to be able to deploy the solution in various locations.
How can I be able to get the local path to use in System.IO
classes from a SignalR?
System.IO.Directory.GetCurrentDirectory()
gives me the location of the IIS worker process.
You can try the following
var path = (System.Web.HttpContext.Current == null)
? System.Web.Hosting.HostingEnvironment.MapPath("~/")
: System.Web.HttpContext.Current.Server.MapPath("~/");
which uses the hostingenvironment to get the path of the executing application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With