show images on site whick located in another server - c#

I have ASP.NET WebApi(MVC) application. On the site I need to show images. This images located on a separate server in the local network. I've tried the following:
<img src='file://///server_name/...'>
I tried various src addresses and only the one worked, but only in the IE, I got error in the Chrome and in the Firefox. I know it's security limitations.
And, I have question, What is best approach to get images from the separate server? I have WCF applciation also on main server. May be there are exist some way or may be to write console application(or another one web applciation) and host it on the images server, and it's applciation will serve http requesst from my main site? The perfomance is main goal for me.
I can't move images because there are hundreds terabytes. And I don't want to use ASP.NET Impersonation.

Map a Virtual Directory in IIS Manager. More info here.
And then reference the image:
<img src='/MyVirtualDirectory/photo.jpg'>

Related

Is there any way to access clients(users) special folder from web application hosted in web server

I'm developing a web application using MVC which is hosted in web server. Whenever a user accesses the application, it has to fetch the local app data folder from the clients machine.
Is there any possible way to achieve the above mentioned scenario?
I have tried using Environment.Specialfolder, but it is giving the path of web servers local data not the path of client's machine
C# :
string s = Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData);
Server-side code cannot just access files on client's machine. Instead, this functionality should be implemented with client-side scripts.
If you need to let your app persist some data or file on user's machine, and later read that data and send it to the server (or use it on the client), you have plenty of options in the modern browsers:
Cookies
localStorge
IndexedDB
fileSystem API, though it's not part of the standard, so be careful
Fetching an arbitrary file from user's machine is a totally different story, because it has security implications. Here your options are:
Put <input type="file"> on a page and let the user pick a file that will be uploaded to the server.
Use HTML Drag & Drop to let user drag a file onto your page
Develop an accompanying desktop application, which the users will have to install on their machines.
You may also explore the possibility of developing a browser extension, though this will give you very limited access to user's file system, AFAIK. Today the major standards are Web Extensions for mainstream browsers, and Browser Helper Objects for Internet Explorer.

File Drag&Drop from Browser to Browser

My asp.net web application is some kind of "document managment system" saving files in the file system of the server.
The stored files are shown in an asp:ListView control and are downloadable as HTTP- Download. But I also want to drag&drop them into another browser window to upload the draged file to an cloud storeage like dropbox or google drive oslt.
I did some research and I didn't find any solution for this problem. I don't know if this is even possible. Maybe someone has an idea how this could be done?
I am pretty sure you can't have a web application doing that for you because it involves having your web language interacting with your computer, to move a local file to another window or tab in the browser.
It would be similar to have Javascript accessing your local files without the user "help". That is not allowed.
Rather than doing that, why not connect to Google Drive or Dropbox API and make the upload yourself?
In the piece of code where you trigger the download, you could also trigger an upload to the desired service.
Here are the API Documentation for the mentioned services:
https://www.dropbox.com/developers/documentation/http/documentation#file_requests-create
https://developers.google.com/drive/api/v3/manage-uploads

Load asp.net website inside winform C#

I have a(n) (MDI) Windows Form application. It contains two forms. One form (Measured data) controls an engine, another form (laboratory) should show my asp.net web site that has various assignments for the user to do.
How can I show the asp.net default page in that laboratory form? I'm using awesomium to make a browsing window in my laboratory form.
Doing the following
webView.LoadURL("file:///D:/school/4e%20jaar/Erasmus/ErasmusProject/Laboratory/deault.aspx");
gives an error. Probably because the asp.net site isn't online. but how can I run the site so I can see the default.aspx page?
I have on solution with three projects
ErasmusProject
ASP.NET website
SIMOclasses
SIMOForm
The problem is you cannot execute aspx files with file:/// path.
You have to execute on IIS.
So first thing you have to do setup iis if you didnt, create new web site (or use Default Web Site) to execute your aspx files, than change your link file:/// to http://localhost or something.
The URL you've specified looks like its accessing the raw file via the file system. i.e. file:///D:/.../default.aspx.
(You've also misspelt 'default' in your question!)
Can you access that URL from a browser (e.g. IE, Firefox, etc) and see the content you want? I suspect you can't and that you're missing the webserver that is compiling and serving the .aspx pages.
You should host your website first :
WebDev.WebServer /port:9999 /path:"C:\Projects\MyWebSite"

ASP.NET: Clustered environment communication Problem

I'm pretty noob with ASP.NET programming and i'm a bit confused on a problem that i'm facing right now.
We, as devs in my company, live in a clustered environment like the one shown in figure
Nothing really special.
You see, IIS Websites are duplicated on evry FrontEnd Servers. Business logic resides on BackEnds that are sitting, togheder with DB and NAS File system, behind a firewall.
So communication between the public space and the protected one is permitted only through particular channels, with particular requests, to particular IPs and Protocols.
Now, we were asked to build a site where the user can customize his own environment, upload images that will be dispalyed in his HomePage and other features.
In a classical configuration, a user upload an image that is written in a folder in the site root, and then the HTML refers to that image to populate whatever control to display it.
But, when a user connect to our site, the load balancer will choose one particular frontend that's not the same for evry session.
So, a user will upload his file, disconnect and then come back only to find that his image is gone, 'couse the Load Balancer has routed his request to a differnt frontend where the image does not exist.
So the need to write a piece of code that pull the file from the NAS behind the Firewall.
The upload part is stupid, and i can understand it.
My problem is:
when the user connects to his page, how i reference in the HTML an image that's not on the machine the site is running on but on a completely hidden File system?
I thought of writing a WCF that serve the image as as a byte stream, but which ASP.NET control to use on the Page to put the stream content on, and How?
I Know that asking the experts community will bring me the best way to accomplish this.
Hope this is clear enough.
Thanks so much for the replays and excuse me for the bad english form.
Instead of using your file system for User Images, i would recommend you to go for some CDN solution like Amazon S3 or some other you like. This way you don't need to take care of where the image is stored or requested from, it shall always be accessed through CDN url(given when you upload an image on CDN programmatically), where url shall be in your database.Using a CDN releives you of many concerns that you shall face while storing at your location.
Even though if you don't like to use S3 , then your option is good enough to develop a simple WCF/WEB service to upload/serve the images.

Passing file data between Administration app and Web site app

We have two separate web applications for a site: One for the site itself, and one for the cms/administration side. I'm not sure why the original developer designed it this way, but whatever.
I am tasked with adding some functionality to the administration side that uploads files. These files then need to exist within the folder structure of the actual site. I was thinking I might have to write a web service that sits on the actual site that accepts the file bytes and file name from a call within the administration site, and creates the file in the correct folder, but I was wondering if anyone had any ideas about a cleaner way to accomplish the same thing.
In general, how would you tackle a scenario where you upload a file on one site, and send it to the directory structure in another?
Thanks in advance!
The solution I ended up going with is to store the full file path to the other site in the web.config. It's not the most elegant solution, but it works and I'm mildly happy with it since it is easily maintainable across dev/staging/production.
You could create a Windows Service to transfer the uploaded files from one folder to another.
After a file is uploaded on the admin site, the windows service moves the file over to the correct location on the other site. You just need to decide how to communicate with the service - you could add details about the uploaded file to a message queue that the service monitors or perhaps you windows service might just watch the upload folder for any new files.

Categories