views:

390

answers:

3

I've just been tasked with abstracting the admin section of a website to its own separate domain on a separate (shared) hosting plan. Part of what the admin section does is upload pictures for products. Now that this admin section is no longer a part of the main domain, how can I upload products onto the main domain from the admin domain?

I'm using ASP.NET/VB.NET.

Thanks

EDIT Let me add that both systems are on shared hosting plans, so I don't really have any sort of ability to map drives or anything. I was looking for a programmatic way. Is there a way to have one site "call" the other and tell it which files to save onto the server?

+2  A: 

If they're on the same box, you can have one site write to the other site's file system (given the right permissions). But this sounds like it won't work in your shared hosting environment, though.

Otherwise, you could provide a URL for the main app to load images from the admin app, just make sure the images are saved to a place where they're accessible to the public.

JMP
so no way to actually upload images remotely to another host?
Jason
It sounds like what you'd like is a Server.Transfer() to another domain, which simply won't work. You could window.open() to a page on your main site that handles file-upload, but I feel like that would be kludgy.
JMP
i may have to settle for kludge... would an iframe potentially work, where i call a page from the main site whose job is to only upload pictures?
Jason
Another option would be to have a web service that copies the files from your admin site to your main site. But no, you can't upload directly from admin domain page to a main domain resource.
JMP
I'm not confident an iframe would work because of XSS-style attacks, might be worth a try, though!
JMP
ok, how would i do that? that sounds like a great idea...
Jason
I'd imagine that main site would have a web service that takes a filestream and a filename that you could invoke from the admin site. Take the filestream from the fileupload control and pass it directly to your main site's fileupload web service.
JMP
hm... could you provide a code snippet? i would be eternally grateful :)
Jason
I will dig out a snippet this evening when PHB isn't looking :)
JMP
haha thanks!
Jason
I found an article that demonstrates how to create a fileupload web service and upload a file via a WinForms app. It would be fairy easy to modify for .ASPX. Hopefully this will get you off the ground: http://tinyurl.com/oagr4z
JMP
THANK YOU. That article got me on the right track. After a bit of work on how to convert a stream into a byte array and choosing a .ashx over a webmethod, i got this working. again, i wish i had more points to give you. thank you so much.
Jason
A: 

I have not yet found a more elegant solution, so I'm hoping you'll get a better answer than mine. I'm also not sure if this is even possible based on your setup.

What I normally do in this case is to do one of two options. Both involve mapping a network drive from the server where the images are uploaded to and then copying the files from the admin site to the main site.

Either I copy the files as soon as they are uploaded, or I write a separate script to copy the files. Possibly, on the Admin site, I would list the files that need to be copied and do the copy on a button click.

EDIT - added after the fact

This is one of those challenges that comes up regularly for me. Due to the extra overhead involved, I almost never put my admin site on a different server than the main site. The above methods are used only where I absolutely need to do this.

David Stratton
i have to do this because in the event that the main site goes down, the admin site can still function. like right now.
Jason
Are you able to map a network drive from your admin server to the main site server? If so, I can add a code snippet for clarification on how to accomplish this.
David Stratton
unfortunately i have no server access... both are on shared boxes :\
Jason
That's too bad. Then I like @presleyster's idea of having a web service.. On the main site, you can do a web service that accepts an Image as a parameter, and call the web service from your admin site's upload code. I'm giving him an upvote for the sggestion. I hadn't thought of that.
David Stratton
+1  A: 

You can setup a webservice on the non-admin domain that will be called by the admin domain. So when you upload a new image in admin you:

  • select the file to upload
  • submit the form (postback)
  • in the file upload event handler, call a web service on the non-admin domain with necessary details (name, content, etc)
  • in the webservice, you save the file, update a db, etc. and return whatever data is necessary for the admin page to know where the image is stored
  • the admin page continues processing

It is far from being as easy as sharing a folder, but it would work.

Is the money saved on a shared server worth the time of implementing this? Who knows...

ADB
yes, it's absolutely worth it. the abstraction must be made. do you have a code snippet as to how this could work? i'm not sure how to post an image to another site
Jason