Hi all, I am using MVC 3, MVCContrib areas and have a little snag. I have a core application that manages all of the common activities for all of my applications. Each of my applications is then an MVCContrib area which gets registered at run time. Each
of these areas may also continue some application specific styling other than the core source. What I need to do is, at run time, check if a specific custom stylesheet exists within an area at runtime. This is where my problem lies. When I try to do File.Exists
then the path that is returned is not relative to my area but is relative to my core website. So basically if I have an application (area) called "App1" and I try to do "Server.MapPath("~/Treatment/Content/")" the path that is returned is something like "d:\\websites\applications\core\content"
but I need to check "d:\\websites\applications\app1\content"
I kmow the content is compiled into a dll for each of my applications so maybe this is the problem?
ASP.NET abstracts the filesystem with something called a VirtualPathProvider. This is the API that is used to find files (and the API that PortableAreas implements to load views from the DLL). Try this instead:
I was thinking about that however I have all of my files properties set as 'Content' and they already compile into a dll. I was wondering about the embedded resource so I tried it but this now complains about duplicate resources. I will have to look again.
Scout7
Member
76 Points
212 Posts
MVC 3, MVCContrib Areas & File Exists Problem
Mar 28, 2012 10:27 AM|LINK
Hi all, I am using MVC 3, MVCContrib areas and have a little snag. I have a core application that manages all of the common activities for all of my applications. Each of my applications is then an MVCContrib area which gets registered at run time. Each of these areas may also continue some application specific styling other than the core source. What I need to do is, at run time, check if a specific custom stylesheet exists within an area at runtime. This is where my problem lies. When I try to do File.Exists then the path that is returned is not relative to my area but is relative to my core website. So basically if I have an application (area) called "App1" and I try to do "Server.MapPath("~/Treatment/Content/")" the path that is returned is something like "d:\\websites\applications\core\content" but I need to check "d:\\websites\applications\app1\content"
I kmow the content is compiled into a dll for each of my applications so maybe this is the problem?
Anybody got any ideas?
BrockAllen
All-Star
28042 Points
4991 Posts
MVP
Re: MVC 3, MVCContrib Areas & File Exists Problem
Mar 28, 2012 12:47 PM|LINK
ASP.NET abstracts the filesystem with something called a VirtualPathProvider. This is the API that is used to find files (and the API that PortableAreas implements to load views from the DLL). Try this instead:
System.Web.Hosting.HostingEnvironment.VirtualPathProvider.FileExists("~/Content/Foo.css")
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
Scout7
Member
76 Points
212 Posts
Re: MVC 3, MVCContrib Areas & File Exists Problem
Mar 28, 2012 01:27 PM|LINK
Hi, thanks for your reply however that function returns false even though I can see the file inside of area. Maybe I am missing something?
BrockAllen
All-Star
28042 Points
4991 Posts
MVP
Re: MVC 3, MVCContrib Areas & File Exists Problem
Mar 28, 2012 01:34 PM|LINK
Hmm, works for me... so did you remember to mark the view/content files as Build Action "Embedded Resource"?
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
Scout7
Member
76 Points
212 Posts
Re: MVC 3, MVCContrib Areas & File Exists Problem
Mar 28, 2012 02:03 PM|LINK
I was thinking about that however I have all of my files properties set as 'Content' and they already compile into a dll. I was wondering about the embedded resource so I tried it but this now complains about duplicate resources. I will have to look again.