I have a deployment issue with my aspnetcore 3.1 api project that I don't understand.
Generally, run the aspnetcore project against IIS Express, then test it using postman.
It works in this configuration, however, if I attempt to run against my local iis, it fails on a database connection.
I am running against my local instance of SqlServer. Here is my api configuration:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iis": {
"applicationUrl": "http://localhost/MyAPIProject",
"sslPort": 0
},
"iisExpress": {
"applicationUrl": "http://localhost:56232",
"sslPort": 44319
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"BeeTherrAPI": {
"commandName": "IIS",
"launchBrowser": true,
"launchUrl": "api",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
In both cases iis express and iis, I am running against the same db connection string:
"Server=(localdb)\\MSSQLLocalDB;Database=BeeTherrAPI;Trusted_Connection=true"
is there an issue with iis accessing a localdb connection string?
When you run it on local iis, is there any error message? And ensure your website’s domain account has permissions to access the database.
Best regards,
Jerry Cai
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
When I run against iis, I need to run VS with elevated credentials.
there does not appear to be a problem starting the instance.
Running under IIS Express, the site is https://localhost:44309/api
Running under IIS Desktop, the site is https://localhost:45000/ProjectName/api
The error message in postman is: connect ECONNREFUSED 127.0.0.1:45000
I will note that in the successful call to IIS Express the first two lines of the postman response is:
GET https://localhost:44309/api/host
Warnig: Unable to verify the first certificate
I initially thought it was a cors issue but I added the following to my startup configure:
app.UseCors(options => options.AllowAnyOrigin());
but it makes no difference.
the sql database in also local on my machine. I would not think that there would be a dB permission problem,
besides, the issue appears to be a connection to the website issue.
I follow the official ASP.NET Core deployment documentation. Setup the IIS application according to the docs. Then all you have to do is publish to the application folder setup in IIS.
This is like having a dev and text environment on your local machine. Development and debugging continues against the development source. You have the ability to run the app in a hosted environment where you can test configuration. This setup is also
handy for developing code against REST services where the REST services are known to function as expected.
Member
2 Points
23 Posts
Deploying aspnet core api to desktop iis
Dec 09, 2020 12:37 AM|Robotuner|LINK
I have a deployment issue with my aspnetcore 3.1 api project that I don't understand.
Generally, run the aspnetcore project against IIS Express, then test it using postman.
It works in this configuration, however, if I attempt to run against my local iis, it fails on a database connection.
I am running against my local instance of SqlServer. Here is my api configuration:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iis": {
"applicationUrl": "http://localhost/MyAPIProject",
"sslPort": 0
},
"iisExpress": {
"applicationUrl": "http://localhost:56232",
"sslPort": 44319
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"BeeTherrAPI": {
"commandName": "IIS",
"launchBrowser": true,
"launchUrl": "api",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
In both cases iis express and iis, I am running against the same db connection string:
"Server=(localdb)\\MSSQLLocalDB;Database=BeeTherrAPI;Trusted_Connection=true"
is there an issue with iis accessing a localdb connection string?
Participant
780 Points
260 Posts
Re: Deploying aspnet core api to desktop iis
Dec 10, 2020 09:27 AM|Jerry Cai|LINK
Hi Robotuner,
When you run it on local iis, is there any error message? And ensure your website’s domain account has permissions to access the database.
Best regards,
Jerry Cai
Member
2 Points
23 Posts
Re: Deploying aspnet core api to desktop iis
Dec 10, 2020 01:33 PM|Robotuner|LINK
Thanks Jerry.
When I run against iis, I need to run VS with elevated credentials.
there does not appear to be a problem starting the instance.
Running under IIS Express, the site is https://localhost:44309/api
Running under IIS Desktop, the site is https://localhost:45000/ProjectName/api
The error message in postman is: connect ECONNREFUSED 127.0.0.1:45000
I will note that in the successful call to IIS Express the first two lines of the postman response is:
GET https://localhost:44309/api/host
Warnig: Unable to verify the first certificate
I initially thought it was a cors issue but I added the following to my startup configure:
app.UseCors(options => options.AllowAnyOrigin());
but it makes no difference.
the sql database in also local on my machine. I would not think that there would be a dB permission problem,
besides, the issue appears to be a connection to the website issue.
All-Star
52201 Points
23277 Posts
Re: Deploying aspnet core api to desktop iis
Dec 10, 2020 02:31 PM|mgebhard|LINK
I follow the official ASP.NET Core deployment documentation. Setup the IIS application according to the docs. Then all you have to do is publish to the application folder setup in IIS.
https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-5.0&tabs=visual-studio
This is like having a dev and text environment on your local machine. Development and debugging continues against the development source. You have the ability to run the app in a hosted environment where you can test configuration. This setup is also handy for developing code against REST services where the REST services are known to function as expected.
I typically use "dotnet run watch" to startup services during dev. That way you can see exceptions and logs in the console. The watch switch recompiles the code after making a change. https://docs.microsoft.com/en-us/aspnet/core/tutorials/dotnet-watch?view=aspnetcore-5.0
Member
2 Points
23 Posts
Re: Deploying aspnet core api to desktop iis
Dec 11, 2020 03:08 PM|Robotuner|LINK
Thanks for you help. I believe my environment was corrupt and I ended up deleting the .vs folder as described here:
https://stackoverflow.com/questions/37352603/localhost-refused-to-connect-error-in-visual-studio
That didn't completely solve the issues, I finally went into the web.config folder and removed an environmentVariable the set the ssl port to 45000.