1

I want to use the default implemented VirtualPathProvider of ASP.Net MVC Web Application.

In other words I want to inherit my own VirtualPathProvider from default Asp.net VirtualPathProvider and just override the GetCacheKey Method.

What should I do?

Anyone can help?

Cheers

tereško
  • 58,060
  • 25
  • 98
  • 150
Manoochehr Dadashi
  • 715
  • 1
  • 10
  • 28

1 Answers1

1

Create your custom virtual path provider class, overriding the method you want, and then call HostingEnvironment.RegisterVirtualPathProvider from within Application_Start (defined in global.asax.cs) to install it:

protected void Application_Start() {
    HostingEnvirontment.RegisterVirtualPathProvider(new MyVPProvider());
}
Jon
  • 428,835
  • 81
  • 738
  • 806
  • Thanks jon, But as you know VirtualPathProvider is an abstract class. So I think I should implement other methods too. or am I wrong??? can you please tell me about this? – Manoochehr Dadashi Aug 18 '13 at 14:59
  • Oh my... That was a really stupid question. I didn't know that abstract classes can have none abstract methods... – Manoochehr Dadashi Aug 18 '13 at 15:05
  • 1
    @abzarak: Of course you should implement `FileExists` and `GetFile`. But yes, there are no abstract methods. – Jon Aug 18 '13 at 15:06
  • So is there not any way to just inherit from default VirtualPathProvider ? – Manoochehr Dadashi Aug 18 '13 at 15:12
  • I noticed that there is not any abstract method to be implemented. So I think it's enough for me to override the only method I want... is it true? – Manoochehr Dadashi Aug 18 '13 at 15:17
  • 1
    @abzarak: Yes, but depending on what you want to do you may also need to override other methods. Example with `System.Object`: you are never forced to override `object.Equals`, but when you do you also have to override `object.GetHashCode`. – Jon Aug 18 '13 at 17:54