title: asp.net core web.api application can't be started
body: <p>I try to deploy asp.net web.api application on CentOS. When I run it manually using dotnet /var/www/html/CoreApiTest.dll it works fine (with apache as the proxy). When I use service to run it I get an error. Here is the service code:</p>
  
  <pre><code>[Unit]
  Description=Example .NET Web API Application running on CentOS 7
  
  [Service]
  WorkingDirectory=/var/www/html/CoreApiTest
  ExecStart=/usr/bin/dotnet /var/www/html/CoreApiTest.dll
  Restart=always
  # Restart service after 10 seconds if dotnet service crashes
  RestartSec=10
  SyslogIdentifier=dotnet-example
  User=apache
  Environment=ASPNETCORE_ENVIRONMENT=Production
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>I install it using <code>systemctl enable kestrel-CoreApiTest.service</code>. Then start it and check status: <code>systemctl status kestrel-CoreApiTest.service</code> and get this error:</p>
  
  <pre><code>kestrel-CoreApiTest.service - Example .NET Web API Application running on CentOS 7
     Loaded: loaded (/etc/systemd/system/kestrel-CoreApiTest.service; enabled; vendor preset: disabled)
     Active: activating (auto-restart) (Result: exit-code) since Thu 2017-11-02 21:27:35 MSK; 5s ago
    Process: 2093 ExecStart=/usr/bin/dotnet /var/www/html/CoreApiTest.dll (code=exited, status=1/FAILURE)
   Main PID: 2093 (code=exited, status=1/FAILURE)
  
  Nov 02 21:27:35 aryumin.fvds.ru systemd[1]: kestrel-CoreApiTest.service: main process exited, code=exited, status=1/FAILURE
  Nov 02 21:27:35 aryumin.fvds.ru systemd[1]: Unit kestrel-CoreApiTest.service entered failed state.
  Nov 02 21:27:35 aryumin.fvds.ru systemd[1]: kestrel-CoreApiTest.service failed.
  </code></pre>
  
  <p>In logs (journalctl -u kestrel-CoreApiTest) I see this:</p>
  
  <pre><code>ov 02 20:59:47 aryumin.fvds.ru systemd[1]: Started Example .NET Web API Application running on CentOS 7.
  Nov 02 20:59:47 aryumin.fvds.ru systemd[1]: Starting Example .NET Web API Application running on CentOS 7...
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: Welcome to .NET Core!
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: ---------------------
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available command
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: Telemetry
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: --------------
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: The .NET Core tools collect usage data in order to improve your experience. The data is anonymous a
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 usi
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: System.UnauthorizedAccessException: Access to the path '/usr/share/httpd/.dotnet/2.0.0.dotnetFirstU
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: --- End of inner exception stack trace ---
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 e
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at System.IO.File.Create(String path)
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.Extensions.EnvironmentAbstractions.FileWrapper.CreateEmptyFile(String path)
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.DotNet.Configurer.FirstTimeUseNoticeSentinel.CreateIfNotExists()
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.PrintFirstTimeUseNotice()
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentin
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
  Nov 02 20:59:54 aryumin.fvds.ru dotnet-example[476]: at Microsoft.DotNet.Cli.Program.Main(String[] args)
  </code></pre>
  
  <p>What am I doing wrong?</p>