Last post Jan 30, 2018 09:12 PM by Andre Vene
Jan 29, 2018 06:59 PM|Andre Vene|LINK
I have a simple api application that runs perfectly when executed using "dotnet app.dll" command, but does not work when published in local IIS.
dotnet --version = 2.1.4
I already tried to publish:
- Using command "dotnet publish $ SolutionFilePath -c Release -o $ publishPath"
- Using "Publish" of Visual Studio 2017
IIS configuration is the same as this ->
Jan 29, 2018 07:11 PM|Radomir|LINK
Can you be more precise with "does not work...." -- error? Does event log show you something? etc.. does dotnet.exe even start when going through IIS?
Jan 29, 2018 08:20 PM|Andre Vene|LINK
Hi @Radomir, Thanks for your interest
Yes, dotnet.exe does start through IIS, I can even attach it to VS for debuging.
There's no event log.
There are only the log generated by NLog:
2018-01-29 16:30:54.9676|2|Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker|INFO|Executed action API.SMS.Controllers.MessageController.SimpleSMSSender (API.SMS) in 6107.5797ms
2018-01-29 16:30:54.9871|13|Microsoft.AspNetCore.Server.Kestrel|ERROR|Connection id "0HLB78PGUOQJE", Request id "0HLB78PGUOQJE:00000004": An unhandled exception was thrown by the application.
This is the piece of code that crashes on IIS:
var requestMessage = new HttpRequestMessage(method, uri); -> The uri parameter here, is a HTTPS API
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(item, Formatting.None,
NullValueHandling = NullValueHandling.Ignore
}), System.Text.Encoding.UTF8, "application/json");
requestMessage.Headers.Authorization = new AuthenticationHeaderValue(authorizationMethod, authorizationToken);
var response = await _client.SendAsync(requestMessage); ->
This line crashes with a timeout, only on IIS.
Starting the app using dotnet command, or debugging in VS, it works.
Jan 29, 2018 10:46 PM|Radomir|LINK
Can we try a little trick? Go into IIS settings and change app pool identity to run under your account instead of the default...
When you run dotnet.exe from command line, it runs as you (and inherits your login account "settings" and privileges).. when dotnet.exe gets spawned by IIS, it runs under same identity as AppPool (that spawned it) and won't have access to any user-specific
settings that you may have for your login account (that you logged into the machine with).
Looks like you're sending some request out -- do you have some proxy in between (ie a user-specific proxy)? Your personal proxy settings won't get carried over to app pool's identity.. hence it could have issues making outgoing calls.
Does other stuff in the controller work (like normal stuff that doesn't make any outgoing calls)?
Jan 30, 2018 02:03 AM|Edward Z|LINK
>> The uri parameter here, is a HTTPS API
For this, do you configure HTTPS in IIS?
I suggest you try Fiddler to capture the request, and share us the response.
To check the response from IIS, I suggest you try PostMan to send this request, and share us the response.
Jan 30, 2018 09:12 PM|Andre Vene|LINK
The odd situation was that if the application was published on another machine, it worked fine.
I had 2 versions of Visual Studio installed (Community and Professional).
So I removed the community version and did the changes you described on IIS AppPool identity.
Now it works.
Thank you very much!