如何将本地II与SQL Server数据源连接?

发布于 2025-02-10 17:10:36 字数 745 浏览 0 评论 0原文

我在本地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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文