You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET Core迁移至HostGator后API路由出现ERR_HTTP2_PROTOCOL_ERROR问题

问题排查:ASP.NET Core API在HostGator部署后出现ERR_HTTP2_PROTOCOL_ERROR

本人是ASP.NET新手,正在为SQL Server数据库开发简易API。该项目原本在Azure上正常运行,因额度耗尽且Azure托管成本过高,转至HostGator搭建新数据库并部署。目前项目首页www.myurl.com/home可正常访问,但访问API路由www.myurl.com/api/models或www.myurl.com/api/models/{id}时,出现ERR_HTTP2_PROTOCOL_ERROR提示无法访问站点。以下为项目相关代码及配置信息,恳请协助排查问题,如需补充其他信息请告知:

相关代码及配置

ModelsController代码

namespace DotNetCoreSqlDb.Controllers.Api 
{
    [Route("/api/models")]
    public class ModelsController : Controller
    {
        private readonly MyDatabaseContext _context;
        private readonly IDistributedCache _cache;
        private readonly string _ModelItemsCacheKey = "ModelItemsList";

        public ModelsController(MyDatabaseContext context, IDistributedCache cache)
        {
            _context = context;
            _cache = cache;
        }

        // GET: Models
        [HttpGet("/api/models")]
        public IActionResult Get()
        {
            var models= _context.Model;
            
            if (models == null)
            { 
                return NotFound();
            }

            return Json(models);
        }

        // GET: Model{id}
        [HttpGet("/api/models/{id}")]
        public IActionResult Get(int? id)
        {
            var models = _context.Model;
            var model = models.Where(model=> model.model_id == id);

            if (model == null)
            { 
                return NotFound();
            }

            return Json(model);
        }
    }
}

Program.cs路由配置

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Models}/{action=Index}/{id?}");

appsettings.json连接字符串配置

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "LocalSqlServer": "data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
  }
}

Plesk ASP.NET设置(翻译后)

-.NET运行时版本:ASP.NET Core 6.0.28
-托管管道模式:集成
-启用32位应用程序:否
-加载用户配置文件:是
-限制请求实体大小:30000000字节
-快速CGI超时:300秒
-最大请求队列长度:1000
-超时:120秒
-最大并发请求数:4000
-最大并发应用程序池:10

内容的提问来源于stack exchange,提问作者Zachary Lehmann

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 16:23:06