barrypicker
barrypicker

Reputation: 10108

When running ASPNET Core application in Ubuntu 16.04 how can I access a file in another folder?

I am trying to run an ASP5/MVC6 ASPNET core application in Ubuntu 16.04 using dotnet core 1.1. My application resides in one directory off of the users home directory, and another directory off the home directory holds a folder structure with image (.jpg) files.

I am receiving the following error...

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0]
An unhandled exception has occurred: Access to the path '/home/myuser/myimages/somefolder' is denied.
System.UnauthorizedAccessException: Access to the path '/home/myuser/myimages/somefolder' is denied. ---> System.IO.IOException: Permission denied

Here is an example of the folder structure...

/home/myuser/mywebapp/mywebapp.dll

/home/myuser/myimages/somefolder/someimage.jpg

I Have chmodded the following directories to 777..

... and I have chmodded file someimage.jpg to 777 as well.

I am running the aspnet core application from /home/myuser/mywebapp. I have tried sudo and no good.

Can I reference files in ASPNET Core web app that are in a directory outside of the working directory?

Upvotes: 1

Views: 2431

Answers (2)

cheergo
cheergo

Reputation: 1

you can use 'ln' to Make a Link to '/home/myuser/myimages' in your working directory

then you can reference files in your working directory

Upvotes: 0

Alexan
Alexan

Reputation: 8637

By default static files should be located in the wwwroot folder, which inside you working folder. But if you want to keep them outside you can configure the static files middleware:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseStaticFiles();

    app.UseStaticFiles(new StaticFileOptions()
    {
        FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), @"MyStaticFiles")),
        RequestPath = new PathString("/StaticFiles")
    });
}

See tutorial here.

Upvotes: 2

Related Questions