简体   繁体   中英

Uploading images to another site hosted in IIS

I have a solution with MVC and WebAPI projects. They are both hosted in IIS as, for example: http:/mvc.com/ and http:/webapi.com/ . When WebApi recieves images, it saves them at Content/Images/ folder of WebAPI folder using the path generated by the following line of code:

System.Web.Hosting.HostingEnvironment.MapPath(@"~/Content/Images/<imagename>.jpg");

How do I configure things to get it saved in Content/Images/ folder of mvc project ? I try to compose the following path:

@"http:\mvc.com\Content\Images"

But I get error: URI formats are not supported And when it's like this:

@"mvc.com\Content\Images"

I get error: "A generic error occurred in GDI+."

I would suggest to create a folder outside both projects and share that folder between the two.

You can make a setting in your web.config to save the directory path in. This code works for either solution (whether you keep the images in one project or external).

Add this to your web.config file:

<appSettings>
  <add key="imageFolder" value="C:\somewhere"/>
</appSettings>

And this to your C# file to get the location:

var wc = WebConfigurationManager.OpenWebConfiguration(null);
string folderPath = wc.AppSettings.Settings["imageFolder"]?.Value;

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM