Search code examples
asp.net-coreiiswindows-server-2012blazor-server-sideiis-10

Deploying Asp.net Core 3.1 does not work on Windows server


I have this Asp.net Core 3.1 developed on VS2019 preview. basically it is a blazor server-side app with referenced assemblies and some nugets.

it runs fine on VS2019 and on my IIS after publishing to folder.. problem is when i move that folder to windows server machine with IIS installed and everything. an error with 500 code appears.

one thing i noticed here..the log_error.txt file in the server it points out an exception ,and that exception -what ever it is- showing the error line of the startup.cs file with my laptop directory path !

i mean it shows this C:/mrmeeez/..../Startup.cs line 411

but this path does not exists in the windows server machine it supposed to be F:/.... somthing/Startup.cs line 411

i don't know if it has something too do with the problem anyway..or maybe my assemblies and nugets not shipping correctly to the server

windows server machine is working fine , i tried blazor app template and it ran perfectly. i need your help guys , Thanks !


Solution

  • Ok , i found it

    i don't know for sure is this related to asp.net core 3.1 because i deployed asp.net core 2.1 months ago and it was fine

    anyway i used the development exception page in the final publish to see what causing the error and showed this

    UnauthorizedAccessException: Access to the path 'C:\Windows\system32\config\systemprofile\AppData\Local\ASP.NET\DataProtection-Keys' is denied.

    and after searching for that i found the answer from a guy in github it seems that the user IIS_IUSRS for this application pool -by default- does not have permissions to access that path

    to solve this problem,either one of the two below:

    1-Give IIS_IUSRS permissions to access the system files -NOT RECOMANDED-

    2-Change the user of the your application pool to LocalSystem account in IIS by going to Application Pools -> Right-Click your app -> Advance Settings -> Process Model section then change Identity

    Reference: https://github.com/dotnet/aspnetcore/issues/1983

    Thanks!