I have a web application with an admin panel. The admin panel is a webform project and I also have an MVC project to list products inserted in admin panel. But when I upload images to ProductImgs folder in webform project, how can I get them from MVC project? Or can I save them to the MVC project folder?
2 Answers
Ok so sounds like you are trying to share images between two web applications? EDIT Also you are trying to do this using Cassini (the inbuilt dev web server).
The easiest way to do this is to move your development environment to using IIS and then create a virtual directory within your mvc project in IIS that points to the images folder in your other site (on your file system). NB Moving to IIS will also have the added benefits of making your solution be more in line with how it will be deployed which IMHO is a great benefit.
Say you call this virtual directory 'images' and it has two images (image1.jpg and image2.jpg).
You can then reference these images from your mvc site by using
<img src="/images/image1.jpg" />
Here is a link on how to create Virtual Directories.

- 3,498
- 1
- 24
- 25
-
ok but how can i do it on development? when i start debugging mvc project i want to see these pictures in webforms application. – mehmetserif Dec 21 '11 at 10:56
-
Can you paste some source code to show more clearly what you are asking? Cheers. – Dave Walker Dec 21 '11 at 11:07
-
there is no source code to show because i want to know which way is the best way. i upload the image to webform application's ProductImgs folder and insert the image url to database. then i show that image on mvc application but its url is pointing webforms folder. how can i solve this issue? in live application it looks like www.domain.com/admin/images/product/a.jpg but in development localhost:1267/ is pointing working mvc application, and the webform application is not in debug mode so "../admin/images/product/a.jpg" won't be the correct url for an image.. this is my exact problem. – mehmetserif Dec 21 '11 at 11:20
-
Ok so where is the image relative to the root of your mvc project? Have you tried Server.MapPath(imageUrl); ? – Dave Walker Dec 21 '11 at 11:27
-
I keep all the images in webforms applications' images folder. i don't want to copy the same images in mvc applications images folder. Also these two projects are in the same solution. So i think in live website there won't be any problem, problem is in the development site. – mehmetserif Dec 21 '11 at 11:34
-
1Ok the easiest way is to flick to using IIS on your dev machine (or IIS Express if you are on XP - it is halfway between the .net development server and full IIS). You can then create the virtual directory so that the paths will always be the same. Failing that you can try creating what is known as a VirtualPathProvider. – Dave Walker Dec 21 '11 at 12:08
-
You could use the mklink command to create an NTFS directory junction called "images" that points to the real/shared images folder. It's sort of like symbolic links in Unix/Linux world. http://www.howtogeek.com/howto/windows-vista/using-symlinks-in-windows-vista/ – Craig Dec 21 '11 at 12:16
-
Yes Craig is right you can create symbolic links there is a write up on them vs. virtual directories here http://stackoverflow.com/questions/2992112/junctions-or-virtual-directories-for-web-applications . I have always gone the virtual directory path route probably for no other reason than it's pretty easy to do. – Dave Walker Dec 21 '11 at 12:23
-
well now i fixed it with local iis but this time mvc application's web.config is the root and webforms is a virtual directory so webforms web.config inherits from mvc's. I added allowOverride=false to mvc's web.config but this time system.web of webforms' doesn't work. – mehmetserif Dec 21 '11 at 15:55
Now i found the solution: here is the root web.config to solve this issue
<location inheritInChildApplications="false">
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
<add namespace="EkosWeb.Helpers"/>
</namespaces>
</pages>
</system.web>
</location>
I need to add inheritInChildApplications="false" to location.

- 1,185
- 7
- 26
- 48