首页 > 解决方案 > c#在ubuntu 18.04服务器上访问路径被拒绝

问题描述

我和我的朋友想做一个不和谐的服务器。我在 c# 中制作了机器人,需要一些东西来托管它,以便它可以 24/7 运行,我选择了 Digitalocean。我创建了一个 ubuntu 18.04 droplet,在其上安装了 dotnet sdk 并克隆了我的 github bot repo(我知道这不是最好的解决方案)。但是当我尝试这样做时dotnet run,我得到了“访问路径路径''被拒绝”错误。当我在 ubuntu 16.04 上使用 docker 尝试它时,我得到了同样的错误。谁能帮我解决这个问题?(它在 Windows 10 上运行良好)

Dockerfile:

FROM microsoft/dotnet:2.1-sdk
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# copy and build everything else
COPY . ./
RUN dotnet publish -c Release -o out
ENTRYPOINT ["dotnet", "out/Bot.dll"]

错误:

Unhandled Exception: System.UnauthorizedAccessException: Access to the path '/app/out' is denied. ---> System.IO.IOException: Permission denied
   --- End of inner exception stack trace ---
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at Bot.Program.MainAsync() in /app/Program.cs:line 38
   at Bot.Program.Main(String[] args) in /app/Program.cs:line 16

chmod -x 和 chmod -R 777 不起作用

标签: c#linuxubuntuserverdiscord.net

解决方案


您必须为 ubuntu 发布发布,授予执行权限,chmod -R 777 PATHTOPUBLISHFOLDER然后使用path to the file without extension in the publish folder


推荐阅读