SUN
SUN

Reputation: 973

Save files to external(other domain server) server in asp.net

Is it possible to save file to other domain path from file control. I have 2 website www.domain1.com & www.domain2.com. Now I have file control in www.domain1.com & here I want to upload a file which will be store in some directory of www.domain2.com. I don't know is it possible or not. I am trying below basic code but it's not working

if (mainImageUploader.FileName != "")
    {
        System.IO.FileInfo file = new System.IO.FileInfo(mainImageUploader.PostedFile.FileName);
        string newname = file.Name.Remove((file.Name.Length - file.Extension.Length));
        newname = (newname + System.DateTime.Now.ToString("_ddMMyyhhmmss")) + file.Extension;
        mainImageUploader.SaveAs(Server.MapPath("http://www.domain2.com/images/client-store/" + path + newname));
    }

Upvotes: 1

Views: 812

Answers (2)

Siamak Ferdos
Siamak Ferdos

Reputation: 3299

It's not possible. The better way is creating a WebApi to save file on its server on your second website and save file via calling it from your first website.

Each web server only let to each website to access to its root and subfolders or files.

Upvotes: 1

trailmax
trailmax

Reputation: 35126

No, not possible if your other server is configured anywhere near correctly.

You need to enable endpoint on your other server to provide file upload. And probably need to secure it somehow - i.e. with username/password.

Upvotes: 1

Related Questions