abpframework / abp

Open Source Web Application Framework for ASP.NET Core. Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET and the ASP.NET Core platforms. Provides the fundamental infrastructure, production-ready startup templates, application modules, UI themes, tooling, guides and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.31k stars 3.32k forks source link

ABP Application Working on local but not working on IIS #17339

Closed cgdif closed 9 months ago

cgdif commented 9 months ago

Documentation

Please check the official documentation before asking questions: https://docs.abp.io

GitHub Issues

GitHub issues are for bug reports, feature requests, and other discussions about the framework.

If you're creating a bug/problem report, please include the followings:

Please Application is working fine on localhost, but the APIs are not working when hosted on IIS.

appsettings.json { "App": { "SelfUrl": "https://192.168.0.187:44352", "ClientUrl": "http://192.168.0.187:4200", "CorsOrigins": "http://192.168.0.187:4200,https://192.168.0.187,https://192.168.0.187:*,https://*.dbt.com,http://localhost:4435,http://localhost:85,http://localhost:4200,127.0.0.1:80,https://localhost:44352,http://localhost:50278/,http://localhost:80,https://localhost:80", "RedirectAllowedUrls": "https://192.168.0.187:44352,http://192.168.0.187:4200,http://192.168.0.187:*/*,http://192.168.0.187:*/*,http://localhost:4200,https://localhost:44389,https://localhost:44352" }, "ConnectionStrings": { // "Default": "Server=tcp:dbcgdbt.database.windows.net,1433;Initial Catalog=cgdbt-db;Persist Security Info=False;User ID=difadmin;Password=Chhattisgarh.dif@123;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" "Default": "Server=(localdb)\\MSSQLLocalDB;Database=cgdbt;Trusted_Connection=True;MultipleActiveResultSets=true" }, "AuthServer": { "Authority": "https://192.168.0.187:44352", "RequireHttpsMetadata": "false", "SwaggerClientId": "dbt_Swagger" }, "StringEncryption": { "DefaultPassPhrase": "########" }, "Settings": { "IsSelfRegistrationEnabled": false, "Abp.Account.IsSelfRegistrationEnabled": false } }

DBMigrator>appsettings.json { "ConnectionStrings": { // "Default": "Server=tcp:dbcgdbt.database.windows.net,1433;Initial Catalog=cgdbt-db;Persist Security Info=False;User ID=difadmin;Password=Chhattisgarh.dif@123;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" "Default": "Server=(localdb)\\MSSQLLocalDB;Database=cgdbt;Trusted_Connection=True;MultipleActiveResultSets=true" }, "OpenIddict": { "Applications": { "dbt_Web": { "ClientId": "dbt_Web", "ClientSecret": "1q2w3e*", "RootUrl": "https://192.168.0.187:44325" }, "dbt_App": { "ClientId": "dbt_App", "RootUrl": "http://192.168.0.187:4200" }, "dbt_BlazorServerTiered": { "ClientId": "dbt_BlazorServerTiered", "ClientSecret": "1q2w3e*", "RootUrl": "https://192.168.0.187:44318" }, "dbt_Swagger": { "ClientId": "dbt_Swagger", "RootUrl": "https://192.168.0.187:44352/" } } } }

Launch settings: { "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "https://localhost:44352", "sslPort": 44352 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "chhattisgarh.dbt.HttpApi.Host": { "commandName": "Project", "launchBrowser": true, "applicationUrl": "https://0.0.0.0:44352", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }

updated entries in local DB under OpenIddictApplications table.

Stack Overflow

Please use Stack Overflow for your questions about using the framework, templates, and samples:

https://stackoverflow.com/questions/tagged/abp

Use abp tag in your questions.

cgdif commented 9 months ago

Screenshot attached: https://drive.google.com/drive/folders/1HLLm8Piyl9jM7sUguvi6YGyP1UY43CA5?usp=sharing

maliming commented 9 months ago

hi

You can try to get a valid HTTPS certificate and it seems more like a environment.

image
maliming commented 9 months ago

If there is an error you can check the Logs.txt file.

Keertesh commented 9 months ago

If possible shall we get on a call.

Keertesh commented 9 months ago

Shall I use the self sign certificate. As the domain purchasing will happen once the portal will start working on iis.

gterdem commented 9 months ago

Yes, you can use self signed certificate.

cgdif commented 9 months ago

@maliming getting following error on log.txt while hosting on IIS

log.txt output: `2023-08-12 22:48:29.344 +05:30 [INF] Request starting HTTP/1.1 GET https://localhost:44352/ - - 2023-08-12 22:48:31.141 +05:30 [ERR] An error occurred using the connection to database 'cgdbt' on server '(localdb)\MSSQLLocalDB'. 2023-08-12 22:48:31.165 +05:30 [ERR] An exception occurred while iterating over the results of a query for context type 'Volo.Abp.SettingManagement.EntityFrameworkCore.SettingManagementDbContext'. ... ... ...

System.InvalidOperationException: An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure' to the 'UseSqlServer' call. ---> Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot open database "cgdbt" requested by the login. The login failed. Login failed for user 'NT AUTHORITY\SYSTEM'. `

maliming commented 9 months ago

Cannot open database "cgdbt" requested by the login. The login failed.

check the database to see if it exists.

Keertesh commented 9 months ago

Database exists as it is working when running it from visual studio. This is happening when running the application from iis by putting the published folder in a folder.

maliming commented 9 months ago

You can use sql server sa and password in your connection string.

cgdif commented 9 months ago

You can use sql server sa and password in your connection string.

connectiong string used on IIS : Server=(localdb)\MSSQLLocalDB;Database=cgdbt;User ID=sa;Password=●●●●●●●;MultipleActiveResultSets=true;Encrypt=False;TrustServerCertificate=true;Integrated Security=true

attaching the log.txt here:

maliming commented 9 months ago

Please remove Integrated Security=true from the connection string.

cgdif commented 9 months ago

Please remove Integrated Security=true from the connection string.

updated connection string removed Integrated Security=true. Server=(localdb)\\MSSQLLocalDB;Database=cgdbt;User ID=sa;Password=●●●●●●●;MultipleActiveResultSets=true;Encrypt=False;TrustServerCertificate=true

please find the updated log.txt

maliming commented 9 months ago

hi @cgdif

Login failed for user 'sa'.

This is an code problem. You can check the errors in the logs.txt.

cgdif commented 9 months ago

hi @cgdif

Login failed for user 'sa'.

This is a code problem. You can check the errors in the logs.txt.

I checked the logs and tried multiple solutions, but the application is not working on IIS at all, last connection string I tried was. "Server=(localdb)\MSSQLLocalDB;Database=cgdbt;User ID=sa;Password=*****;Trusted_Connection=False;" It would be great if you can look into this once. As the .Net Core application is not working on IIS.

cgdif commented 9 months ago

The same setup is working on IIS Express

maliming commented 9 months ago

How can I reproduce this?

Can you try without localdb?

Keertesh commented 9 months ago

The steps I followed were: Run the application on local.

Published to a local folder.

Create a site and app pool on IIS Keep the published folder as IIS Physical path. Other settings are Local System, No managed code.

Then added 44352 with all unassigned ips in the managed binding.

Added connection string in IIS

Start the application and browse.

maliming commented 9 months ago

Added connection string in IIS

The connection string should be exiting in the appsettings.json file.

Keertesh commented 9 months ago

Yes, keeping the connection string in sync in all the places including the appsettings.json file.

maliming commented 9 months ago

Published to a local folder.

You can also run the app in the publish folder by dotnet yourapp.dll command.

If this work that's mean there is a problem with IIS. and I have no idea about IIS.

Keertesh commented 9 months ago

I clicked the .exe on the published folder then the application was running. Although it was running on localhost with port 5000 is there a way to run it on System IP from the published folder without IIS.

Keertesh commented 9 months ago

The problem is when I run the application on IP from the launch settings on visual studio and run the angular UI from IIS the UI is not able the access the API.

maliming commented 9 months ago

https://andrewlock.net/5-ways-to-set-the-urls-for-an-aspnetcore-app/ https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/web-host?view=aspnetcore-7.0#server-urls

Keertesh commented 9 months ago

Thanks for sharing the urls, let me try this.

cgdif commented 9 months ago

HI @maliming, I'm running the UI (Angular) from IIS and API using dotnet run --urls "http://192.168.29.86:44352" this command but the UI is not able to access the API.

abp api abp ui

maliming commented 9 months ago

Your SSL certificate is invalid.

cgdif commented 9 months ago

Your SSL certificate is invalid.

okay, this same setup works when I run using ng serve --host="IP", please share the url if you have access to bind the self-sign certificate. I generated a self-sign certificate, but it is not showing up while running even when I've imported it and installed it. (Using mmc and IIS)

maliming commented 9 months ago

This is nothing to do with abp. You can get an SSL certificate and set it correctly.

Or you can use localhost and port as your domain names.

https://github.com/abpframework/abp/issues/17339#issuecomment-1676526271

https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-7.0&tabs=visual-studio%2Clinux-ubuntu#trust-the-aspnet-core-https-development-certificate-on-windows-and-macos

Keertesh commented 9 months ago

UI started working on IIS by changing the hostname to localhost. I need to get a ssl for other domains. Thanks @maliming.

Keertesh commented 9 months ago

Application keep on loading even after removing the ssl. When running on LAN and accessing over network.

maliming commented 9 months ago

hi @Keertesh

Check your application logs.

cgdif commented 9 months ago

hi @Keertesh

Check your application logs.

2023-08-22 13:15:44.004 +05:30 [ERR] An exception occurred while iterating over the results of a query for context type 'Volo.Abp.OpenIddict.EntityFrameworkCore.OpenIddictDbContext'. System.Threading.Tasks.TaskCanceledException: A task was canceled.

maliming commented 9 months ago

The full logs.

cgdif commented 9 months ago

An exception occurred while iterating over the results of a query for context type 'Volo.Abp.OpenIddict.EntityFrameworkCore.OpenIddictDbContext'. System.Threading.Tasks.TaskCanceledException: A task was canceled.

logs.txt

maliming commented 9 months ago

Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid column name 'commens'.

It seems your migrations file is not up to date. Please check it.

cgdif commented 9 months ago

Invalid column name 'commens

logs are further down I updated the migration, but the issue persists. getting token has expired, error validating the token in the Ui console.

-- also please suggest on changing the default UI url from http://10.132.29.185 to http://10.132.29.185/abc

maliming commented 8 months ago

You can also check the logs from your SQL server.

cgdif commented 8 months ago

You can also check the logs from your SQL server.

@maliming When I'm login then I'm getting angular-oauth2-oidc.mjs token has expired, it is working fine on the system it is hosted. But when I'm accessing it on a system connected via LAN it is throwing the above error and the screen is stuck on Login and keep on calling the below API. Please suggest as the rest of the parts are working fine on the system it is hosted. http://10.132.29.185/dbt?code=C_pEjz6f1aLePUUztuiAINKwNfFmJk2cw_s4_8IjLlE&state=cnlLOWRCRkZBTkF3ZnpTa2RFcWFtQldlbXo2U2YuUmRHUUs2ODlDc1ZDbC5n

I saw this in the logs: [12:50:06 DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was marked as rejected by OpenIddict.Validation.OpenIddictValidationHandlers+ValidateToken.

Please suggest.

Error log [12:50:06 DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ProcessJsonResponse1[[OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext, OpenIddict.Server, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]. [12:50:06 DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext was marked as handled by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ProcessJsonResponse1[[OpenIddict.Server.OpenIddictServerEvents+ApplyTokenResponseContext, OpenIddict.Server, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]. [12:50:06 DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessSignInContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Exchange+ApplyTokenResponse1[[OpenIddict.Server.OpenIddictServerEvents+ProcessSignInContext, OpenIddict.Server, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]. [12:50:06 DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessSignInContext was marked as handled by OpenIddict.Server.OpenIddictServerHandlers+Exchange+ApplyTokenResponse1[[OpenIddict.Server.OpenIddictServerEvents+ProcessSignInContext, OpenIddict.Server, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]. [12:50:06 INF] Executed action Volo.Abp.OpenIddict.Controllers.TokenController.HandleAsync (Volo.Abp.OpenIddict.AspNetCore) in 89.795ms [12:50:06 INF] Executed endpoint 'Volo.Abp.OpenIddict.Controllers.TokenController.HandleAsync (Volo.Abp.OpenIddict.AspNetCore)' [12:50:06 DBG] Added 0 entity changes to the current audit log [12:50:06 DBG] Added 0 entity changes to the current audit log [12:50:06 DBG] Added 0 entity changes to the current audit log [12:50:06 DBG] Added 0 entity changes to the current audit log [12:50:06 INF] Request finished HTTP/1.1 POST http://10.132.29.190/connect/token application/x-www-form-urlencoded 224 - 200 6009 application/json;charset=UTF-8 114.9607ms [12:50:06 INF] Request starting HTTP/1.1 GET http://10.132.29.190/api/abp/application-configuration - - [12:50:06 INF] Request starting HTTP/1.1 GET http://10.132.29.190/api/abp/application-configuration - - [12:50:06 INF] CORS policy execution successful. [12:50:06 INF] CORS policy execution successful. [12:50:06 DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessRequestContext was successfully processed by OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandlers+InferIssuerFromHost. [12:50:06 DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessRequestContext was successfully processed by OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandlers+InferIssuerFromHost. [12:50:06 DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+InferEndpointType. [12:50:06 DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+InferEndpointType. [12:50:06 DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+InferIssuerFromHost. [12:50:06 DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+InferIssuerFromHost. [12:50:06 DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandlers+ExtractAccessTokenFromAuthorizationHeader. [12:50:06 DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandlers+ExtractAccessTokenFromAuthorizationHeader. [12:50:06 DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandlers+ExtractAccessTokenFromBodyForm. [12:50:06 DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandlers+ExtractAccessTokenFromBodyForm. [12:50:06 DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandlers+ExtractAccessTokenFromQueryString. [12:50:06 DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandlers+ExtractAccessTokenFromQueryString. [12:50:06 DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+ValidateToken. [12:50:06 DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+ValidateToken. [12:50:06 DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was marked as rejected by OpenIddict.Validation.OpenIddictValidationHandlers+ValidateToken. [12:50:06 DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was marked as rejected by OpenIddict.Validation.OpenIddictValidationHandlers+ValidateToken. [12:50:06 DBG] AuthenticationScheme: OpenIddict.Validation.AspNetCore was not authenticated. [12:50:06 DBG] AuthenticationScheme: OpenIddict.Validation.AspNetCore was not authenticated. [12:50:06 INF] Executing endpoint 'Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.AbpApplicationConfigurationController.GetAsync (Volo.Abp.AspNetCore.Mvc)' [12:50:06 INF] Executing endpoint 'Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.AbpApplicationConfigurationController.GetAsync (Volo.Abp.AspNetCore.Mvc)' [12:50:06 INF] Route matched with {area = "abp", action = "Get", controller = "AbpApplicationConfiguration", page = ""}. Executing controller action with signature

Keertesh commented 8 months ago

@maliming @gterdem How to add api prefix in the url.

after the ip or host name

cgdif commented 8 months ago

getting this on IIS, Consider enabling transient error resiliency by adding 'EnableRetryOnFailure' to the 'UseSqlServer' call

cgdif commented 8 months ago

An exception occurred while iterating over the results of a query for context type 'Volo.Abp.BackgroundJobs.EntityFrameworkCore.BackgroundJobsDbContext'

cgdif commented 8 months ago

---> Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the login process. (provider: Named Pipes Provider, error: 0 - No process is on the other end of the pipe.)