如何将本地II与SQL Server数据源连接?
我在本地IIS中托管了.NET Core Web API,遵循以下步骤:
- 将项目发布到
- IIS Manager的文件/文件夹位置,在我从IIS浏览网站时绘制了文件夹位置
,它显示了默认的“ WeatherForeCast”(smame .Net .NET模型)很好。但是,当我尝试浏览开发的页面/控制器时,它一无所获。 请注意,我使用的是SQL Server(本地)的数据源,并使用EF Core Database First方法作为ORM,并且从Visual Studio运行一切都很好。
我认为,我需要在IIS托管期间指出我的数据源。
我尝试在appsettings.json
中使用连接字符串,但它不起作用
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"ConnectionStrings": {
"DBConnectionString": "Server=.\\SQLEXPRESS;Database=TourActivityExpense;Trusted_Connection=True; User ID=sa; Password=sa123;"
},
"AllowedHosts": "*"
}
I hosted .NET Core Web API in local IIS following these steps:
- Published the project into a file/folder location
- In IIS Manager, mapped the folder location
When I browse the site from IIS, it shows the default "WeatherForecast" (sample .NET model) fine. But, when I try to browse my developed page/controller it shows nothing.
Please note that, I am using datasource of SQL Server (locally) and using EF Core database first approach as ORM, and running from Visual Studio everything works fine.
I think, I need to point out my datasource anywhere during hosting in IIS.
I tried to use connection string in appsettings.json
like below, but it didn't work
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"ConnectionStrings": {
"DBConnectionString": "Server=.\\SQLEXPRESS;Database=TourActivityExpense;Trusted_Connection=True; User ID=sa; Password=sa123;"
},
"AllowedHosts": "*"
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论