For various reasons, in development I sometimes want to intercept a request, say ~ / MyStyle.css
What I want to do is make the following snippet:
string absFile = VirtualPathUtility.ToAbsolute(file); return System.IO.File.ReadAllText(absFile);
This absolute path is absolute for the web server, although it will not display on "C: \ whatever". Is there an equivalent method to go to the file system? (Or a ReadFromVirtualPath, etc.?)
ReadFromVirtualPath
Use Server.MapPath()to get the file system path for the requested application path.
Server.MapPath()
string absFile = Server.MapPath(file);
or
string absFile = HttpContext.Current.Server.MapPath(file);
OpenFile VirtualPathProvider, ,
OpenFile
VirtualPathProvider
var stream = HostingEnvironment.VirtualPathProvider.OpenFile(file); var text = new StreamReader(stream).ReadToEnd();
, , VirtualPathProvider, , , css, .