Created
April 23, 2010 02:54
-
-
Save joshuaflanagan/376110 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomViewVirtualPathProvider : VirtualPathProvider | |
{ | |
public override bool FileExists(string virtualPath) | |
{ | |
return File.Exists(HostingEnvironment.MapPath(virtualPath)); | |
} | |
public override VirtualFile GetFile(string virtualPath) | |
{ | |
var customizedVirtualPath = virtualPath.Replace(HostingEnvironment.ApplicationVirtualPath, HostingEnvironment.ApplicationVirtualPath + "/CustomViews/"); | |
return FileExists(customizedVirtualPath) | |
? new CustomViewVirtualPath(virtualPath, HostingEnvironment.MapPath(customizedVirtualPath)) | |
: Previous.GetFile(virtualPath); | |
} | |
} | |
public class CustomViewVirtualPath : VirtualFile | |
{ | |
private readonly string _physicalPath; | |
public CustomViewVirtualPath(string virtualPath, string physicalPath) : base(virtualPath) | |
{ | |
_physicalPath = physicalPath; | |
} | |
public override Stream Open() | |
{ | |
return new FileStream(_physicalPath, FileMode.Open, FileAccess.Read, FileShare.Read); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment