-1

[Edit: I found the issue]

In a .NET Core MVC application, I'm using

File.ReadAllText "/home/username/someDir/file.txt"

function to read text from a file. But it always throws UnauthorizedAccessException

System.UnauthorizedAccessException: Access to the path '/home/username/someDir' is denied. ---> System.IO.IOException: Permission denied

I tried same in Windows and Linux, but getting the same exception. I have given the directory read, write, execute permissions to all users on both Windows and Linux.

Why does it throws IOException in .NET Core? It worked fine with .NET Framework ASP.NET application though.

tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

3

Sorry. I was giving a directory path instead of file path to File.ReadAllText function. The application is working fine now.