I have two MVC applications - Admin and User. Admins would be uploading the images which then would be displayed in the Users application. The images path would be stored in the db, which is shared between the two apps, and using the path the Users app will fetch the image. How would I make the image folder accessible to both apps in Visual Studio and also once the site is uploaded on to the server?
That's really two separate questions:
How do I share the folder in production?
If the sites are on the same server, you can put the shared images pretty much anywhere on the same server. If they are on different servers, you would want to map a network location on both servers to wherever the images are located. In either case, you would then create a virtual directory in IIS on both sites pointing to that shared location.
How do I share the folder in development (ie Visual Studio)?
That's a bit more tricky. Basically, you would need to handle it in the same way as in production, but the problem is that IIS Express is not nearly as transparent as full IIS. I've employed the following method in Visual Studio 2012 and 2013, but the last time I tried it in 2015, it no longer worked. That may have been fixed by now, though, as it's been a while. Regardless, this is pretty much your only option.
Add > New Website...
.Browse...
button on the resulting window.Local IIS
tab.http://localhost:12345/SharedImages
, then you would enter SharedImages
. Make sure that whatever you choose is not an actual existing directory within your project, though.Create IIS application
checkbox.OK
.Cancel
on the previous window.Cancel
again on the original Add New Website Window
. (You're not actually going to add a new website to your solution. This is just the only way to access the place where you can create this virtual directory.) At that point, you should be back to the main Visual Studio window. You won't actually notice any difference in your project/solution, as this was all done in IIS Express. However, if you browse your website and try to load an image under the virtual directory, you should be able to see it in your browser, ie:
http://localhost:12345/SharedImages/foo.jpg
If you see the image, everything is working fine.
If you provide the full url to the users app it will fetch the images no need for other configurations. But be sure that both apps are running and that you are providing full URL not file PATH
[UPDATE] This will work:
Http://domain.com/folder/file.ext
This will not work:
D:\\Hosting\domain\folder\file.ext
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.