How do I move a folder with site resources to another disk?

Volk Volk 551 Reputation points
2023-10-04T11:36:51.9366667+00:00

Hi!

The question is simple, but I couldn't find an answer to it.

I have IIS on Windows Server 2022.
There is a website in the C folder:\inetpub\wwwroot\site.com , which is made on Net technology.Core 6.

There is a website in the folder C:\inetpub\wwwroot\site.com , which is made on Net.Core 6.

There is a folder inside of the site C:\inetpub\wwwroot\site.com\wwwroot\Images, in which images are saved (writing, reading, overwriting).

How do I move this folder (only it) to another disk --> D:\inetpub\wwwroot\site.com\wwwroot\Images or D:\site.com\wwwroot\Images or D:\site.com\Images so that the site works, and all the images exist on another disk?

Is it even possible?

I know there is an option to move the entire inetpub to another disk.

Is it possible to transfer a separate folder with the resources of a separate site?

Is it possible, at least, to move the site separately to another disk, for example like this (C:\inetpub\wwwroot\site.com --> D:\inetpub\wwwroot\site.com)?

Thanks!

Developer technologies | ASP.NET | ASP.NET Core
Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2023-10-05T07:54:06.6166667+00:00

    Hi @volk volk, please allow me to add more information relate to my test result.

    First, I agree with @AgaveJoe to change static file configuration to realize your requirement. I have a method to read file content in my controller, and I also have images folder inside the wwwroot folder.

    public IActionResult Index()
    {
        var rootRoute = Environment.CurrentDirectory;
        try {
            //var route = rootRoute + "\\Cert\\myfile.txt";
    		var route = "C:\\files\\test.txt";
            var content = System.IO.File.ReadAllText(route);
            ViewData["fileContent"] = content;
        }catch(Exception ex) {
            ViewData["fileContent"] = "exception when read the file";
        }
        ViewData["CurrentDirectory"] = rootRoute;
    	return View();
    }
    
    <img src="~/images/Myimage.png" class="img" alt="my image" />
    <img src="~/StaticFiles/images/red-rose.jpg" class="img" alt="A red rose" />
    
    <div>@ViewData["CurrentDirectory"]</div>
    <div>@ViewData["fileContent"]</div>
    

    Like you see, when I didn't set the app.UseStaticFiles(new StaticFileOptions configuration in program.cs, I can still access the file content out of my project, but since it's didn't include into the application, so I can't access the images directly via url localhost:port/myCustomFileFolder/myImg.png

    User's image

    Upon adding the configuration in Program.cs, the image loaded.User's image

    The test above occurred in local VS 2022, and after publishing to IIS(I created a new IIS website which didn't change any other configuration), it worked as well. I trust if you got access denied issue, you might try to change the application pool identity to local system for a test.

    User's image


1 additional answer

Sort by: Most helpful
  1. AgaveJoe 1,510 Reputation points
    2023-10-04T12:00:51.08+00:00

    How do I move this folder (only it) to another disk --> D:\inetpub\wwwroot\site.com\wwwroot\Images or D:\site.com\wwwroot\Images or D:\site.com\Images so that the site works, and all the images exist on another disk?

    The wwwroot folder in the current application is the default location the static file handler looks for static files like, images, css, and js files. The default location can be changed in configuration. Read the official documentation.

    Static files in ASP.NET Core

    Make sure the application pool for the IIS application is granted read/write access to the new folder location.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.