I am very new to MVC and trying to impalement the virtual path provider, and displaying the date time on the screen. The path works fine and recognized by application, however it will not display detetime, instead it just displays the string "Time is: @DateTime.Now". but if i return virtual file directly it will displays the time curectly.
The following code retrieves the Virtual file:
public override VirtualFile GetFile(string virtualPath)
{
//if (virtualPath.StartsWith("/test") || virtualPath.StartsWith("~/test"))
return new StringVirtualFile(virtualPath);
//return base.GetFile(virtualPath);
}
As I mentioned, if I comment out some of the above code as you can see it will display time correctly.
Code for virtual file:
public class StringVirtualFile : System.Web.Hosting.VirtualFile
{
public StringVirtualFile(string path)
: base(path)
{
}
public override System.IO.Stream Open()
{
return new MemoryStream(Encoding.UTF8.GetBytes("Time is: @DateTime.Now"));
}
}
Any suggestions will be appreciated.