ASP.NET核心 - 应用程序在发布后未连接到数据库

时间:2021-11-26 03:31:53

I created a simple ASP.Net Core application with user authentication (so all the Entity Framework has been preloaded into the web app template). It is connecting to my database with the connectionString that is located in my appsettings.json file, with "data source = {computerName}\\{serverName}" setup.

我使用用户身份验证创建了一个简单的ASP.Net Core应用程序(因此所有Entity Framework都已预先加载到Web应用程序模板中)。它使用位于我的appsettings.json文件中的connectionString连接到我的数据库,其中包含“data source = {computerName} \\ {serverName}”setup。

The database instance and Visual Studio are located on the same machine. This works fine in returning data to the web api while within development and debugging mode. When I publish it and try to go to the site from a domain name it does allow me to view the webpages that are not needing database connection but the rest that need data from the database returns pages like this:

数据库实例和Visual Studio位于同一台计算机上。在开发和调试模式下,这可以很好地将数据返回到web api。当我发布它并尝试从域名转到该站点时,它允许我查看不需要数据库连接但其他需要数据库数据的网页返回如下页面:

Error.
An error occurred while processing your request. Development Mode Swapping to Development environment will display more detailed information about the error that occurred.

错误。处理您的请求时发生错误。开发模式交换到开发环境将显示有关发生的错误的更详细信息。

Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.

不应在已部署的应用程序中启用开发环境,因为它可能导致向最终用户显示异常的敏感信息。对于本地调试,可以通过将ASPNETCORE_ENVIRONMENT环境变量设置为Development并重新启动应用程序来启用开发环境。

I have tried to change the Environment Variables for ASPNETCORE_ENVIRONMENT from Development to Production to no success.

我试图将ASPNETCORE_ENVIRONMENT的环境变量从开发更改为生产,但没有成功。

I have tried adding appsettings.Production.json to publishOptions in my project.json file, even though there is no file appsettings.Production.json, and this did not help. dotnet publish

我已经尝试将appsettings.Production.json添加到我的project.json文件中的publishOptions,即使没有文件appsettings.Production.json,这也无济于事。 dotnet发布

Adding the evironment variable in the web.config file did not work Deployment

在web.config文件中添加环境变量不起作用

I need help getting the published web api to connect to my SQL Server database from outside the development Visual Studio setup.

我需要帮助将已发布的web api从开发Visual Studio安装程序外部连接到我的SQL Server数据库。

The last thing I can think of is that maybe I am incorrect in how I understand the connection string. If the web api uses the connection string to connect to the database from the server-side then it should work just fine like it does when in development calling to http://localhost:port# since it's all on the same machine. But, if the database string needs to be based on a client-side call then it would have to be with domain names and IP addresses. Can someone tell me which one it is?

我能想到的最后一件事是,我对连接字符串的理解可能不正确。如果web api使用连接字符串从服务器端连接到数据库,那么它应该可以正常工作,就像在开发中调用http:// localhost:port#一样,因为它们都在同一台机器上。但是,如果数据库字符串需要基于客户端调用,则必须使用域名和IP地址。谁能告诉我它是哪一个?

The only thing else that comes to mind is that there is something I am not doing, and need to do, inside of IIS Manager. I see connect string there as well but unsure what that is for our does since the connection string is inside the application. Also maybe I am suppose to give the app some kind of authorization to communicate with the database server even though they are on the same machine???

我想到的唯一的另一件事是,我在IIS管理器内部没有做,也有需要做的事情。我也看到了连接字符串,但由于连接字符串在应用程序内,因此不确定是什么。也许我想给应用程序一些授权与数据库服务器通信,即使它们在同一台机器上???

1 个解决方案

#1


7  

After much research, finally googling "how to deploy a web api in iis" I was able to learn from Host ASP.NET Web API in IIS using Visual Studio Publish that I needed to add the security entity BUILTIN\IIS_IUSRS. Then placing a mapping to my database tables and giving db_datareader (and possibly db_datawriter) for the database to the IUSER to allow access from my self hosted IIS web api. This from the above mentioned link with the part stating

经过大量研究,最后搜索“如何在iis中部署web api”我能够使用Visual Studio Publish从IIS中学习Host ASP.NET Web API,我需要添加安全实体BUILTIN \ IIS_IUSRS。然后将映射放到我的数据库表中,并将数据库的db_datareader(可能还有db_datawriter)提供给IUSER,以允许从我自己托管的IIS web api进行访问。这可以从上面提到的链接部分说明

Accessing Database under IIS APPPOOL\ASP.NET v4.0 As we are using ASP.NET v4.0 App Pool make sure IIS APPPOOL\ASP.NET v4.0 is added to your Database Server -> Security -> Logins.

在IIS APPPOOL \ ASP.NET v4.0下访问数据库当我们使用ASP.NET v4.0应用程序池时,请确保将IIS APPPOOL \ ASP.NET v4.0添加到数据库服务器 - >安全性 - >登录。

#1


7  

After much research, finally googling "how to deploy a web api in iis" I was able to learn from Host ASP.NET Web API in IIS using Visual Studio Publish that I needed to add the security entity BUILTIN\IIS_IUSRS. Then placing a mapping to my database tables and giving db_datareader (and possibly db_datawriter) for the database to the IUSER to allow access from my self hosted IIS web api. This from the above mentioned link with the part stating

经过大量研究,最后搜索“如何在iis中部署web api”我能够使用Visual Studio Publish从IIS中学习Host ASP.NET Web API,我需要添加安全实体BUILTIN \ IIS_IUSRS。然后将映射放到我的数据库表中,并将数据库的db_datareader(可能还有db_datawriter)提供给IUSER,以允许从我自己托管的IIS web api进行访问。这可以从上面提到的链接部分说明

Accessing Database under IIS APPPOOL\ASP.NET v4.0 As we are using ASP.NET v4.0 App Pool make sure IIS APPPOOL\ASP.NET v4.0 is added to your Database Server -> Security -> Logins.

在IIS APPPOOL \ ASP.NET v4.0下访问数据库当我们使用ASP.NET v4.0应用程序池时,请确保将IIS APPPOOL \ ASP.NET v4.0添加到数据库服务器 - >安全性 - >登录。