1

Here goes:

I have 2 MVC3 projects in the solution, where one is for the Admin and the other is for common Users. The Admin dynamically upload images in a folder in his project. So I want to get that images from the User project to show in same web pages.

I also have three projects that represent the Services, App Logic and the Data Access.

I have been looking for a solution and found same things: 1- Store the image in the database and then retrieve it to User project from a service. 2- Reference the image from the User MVC project. (Couldnt do it)

What is the best aproach? How can i implement the first one?

Thanks!

gonzalomelov
  • 971
  • 1
  • 13
  • 30

2 Answers2

1

Firstly, is there a reason you have two applications and not a single application with an admin area that is authorised users only?

As for storing the image in the database you can convert the image to a byte array and store it as varbinary(max) in your database.

This question shows an example of converting the file stream (I assume you are uploading the image through a form) to a byte array: Convert a bitmap into a byte array

Community
  • 1
  • 1
Adam Goss
  • 1,017
  • 3
  • 14
  • 22
  • There's no restriction in having one or two projects for this. I made this only in case that the projects can be deployed in different servers. I dont really know about Areas, I will read about them – gonzalomelov May 08 '12 at 20:39
  • As I suggested, I would likely recommend using just one web application and use MVC areas to separate the admin functionality. Saving to the database rather than a file could still be a useful step to take as opposed to storing on a file system. Either way would work well. – Adam Goss May 08 '12 at 20:43
  • I see. Something else, the solution I'm implementing is for a multi-tenant application, where the only thing I do to know the tenant is get the subdomain in a controller and then get the information from services with that tenant name. Will I have problems with MVC Areas and multi-tenancy? – gonzalomelov May 08 '12 at 20:48
  • Interesting way of determining users... not sure I would do that myself, but if that is what you are going with I would possibly recommend creating a custom ActionFilterAttribute that can be put on any controllers in the admin area. Within this attribute, put your code for determining if the person can have access to the controller based on the subdomain. If not, redirect them somewhere else – Adam Goss May 08 '12 at 20:53
  • For the multi-tenant, first I tried with Routing but then I saw http://lukesampson.com/post/303245177/subdomains-for-a-single-application-with-asp-net-mvc this post and gave that a chance, I suppose it will work, or at least i hope so. Do you think is not a good aproach? In the link the author not recommend to use areas because it could get very messy. I will try it anyway. Thanks for your response!! – gonzalomelov May 08 '12 at 21:01
  • I would say it depends on the application... if it is for two different shops under the same parent company (going from the example in that link) then it's probably not such a bad idea... for authenticating whether someone is an admin user though, it's not very secure as anyone could go to the sub domain. – Adam Goss May 08 '12 at 21:07
  • First of all it is for the University, it will not be in production. It will be like the example in the link, but for various tenants. Ok, so i will look for areas and see if them fit in the app, otherwise i will try storing the image in the db. Thanks Adam, I really appreciate your help!! – gonzalomelov May 08 '12 at 21:14
0

I guess, you should merge that to one project and use ASP.NET MVC Areas. Create an Area called "Admin" and keep your admin related stuff inside that. Keep your normal user related stuff in the root level. You should be good then. you should be able to share images between these two as you are in the same project.

If you really want to keep it as seperate project and deploy as seperate websites, you should refer the image in the other website by absolute url of the image

Shyju
  • 214,206
  • 104
  • 411
  • 497
  • I will read about Areas. But, I have read http://stackoverflow.com/questions/7584212/get-relative-path-to-image-in-another-project-in-same-solution post but couldnt get it working. Thanks! – gonzalomelov May 08 '12 at 20:41