查看: 72|回复: 0

bug笔记:解决 HTTP Error 500.30

[复制链接]

3

主题

11

帖子

13

积分

新手上路

Rank: 1

积分
13
发表于 2023-1-14 12:45:01 | 显示全部楼层 |阅读模式
先说结论

ef code first 开发的程序,有可能是因为__efmigrationshistory表的数据和开发环境不一致导致的,把这个表完整地复制到发布服务器,就可以解决问题
前言

错误提示:
HTTP Error 500.30 - ASP.NET Core app failed to start
Common solutions to this issue:
    · The app failed to start
    · The app started but then stopped
    · The app started but threw an exception during startup
Troubleshooting steps:
    · Check the system event log for error messages
    · Enable logging the application process' stdout messages
    · Attach a debugger to the application process and inspect
For more information visit: https://go.microsoft.com/fwlink/?LinkID=2028265微软提供的文档:
500.30 In-Process Startup Failure
The worker process fails. The app doesn't start.
The ASP.NET Core Module attempts to start the .NET Core CLR in-process, but it fails to start. The cause of a process startup failure can usually be determined from entries in the Application Event Log and the ASP.NET Core Module stdout log.
Common failure conditions:
The app is misconfigured due to targeting a version of the ASP.NET Core shared framework that isn't present. Check which versions of the ASP.NET Core shared framework are installed on the target machine.
Using Azure Key Vault, lack of permissions to the Key Vault. Check the access policies in the targeted Key Vault to ensure that the correct permissions are granted.有时候在.netcore应用启动后,有时候会遇到500.30错误,从百度和某404网站查,最常见的原因比如有:
1、文件权限设置错误,导致无权访问——整个文件夹授权后可以解决
2、数据库连接字符串错误,导致无法连接字符串——修改字符串即可(大部分其实都是因为开发环境和线上环境配置不一致,导致启动失败)
3、部分文件夹缺失,和程序索引里的文件目录树不一致——手动创建丢失的文件夹,或者重新生成一次程序就好
4、官方文档:可能程序指定的ASP.NET Core 运行时在服务器上未安装——根据程序生成设定,安装管道包就好了,比如我用的是 .Net 5.0,就可以在这个网址下载(点击跳转到微软官方下载地址)
5、官方文档:Azure Key Vault未授权——去后台正确给了授权就可以(这个我没用过)
<hr/>缘起

以上是经常能见到的问题,但是有时候不太够用……


这里有一个思路清奇的解决方案(可能仅限我的特殊情况)
我的程序使用 ef code first 开发,数据库完全使用程序包管理控制台的命令生成,即:
Add-Migration description //更新列表

Update-Database //更新数据库缘兴

在初次在服务器上完成部署后,因为测试过程中,已经有添加了数据到后台,后续改了程序以后,就直接发布了,这个时候第一次报错
各种查,发现可能是因为我的数据库结构没同步,,所以在后续更新过程中,对于我再新增的表,直接使用sql语句来一个一个同步创建到了测试环境里,这个时候再运行,发现还是一样的报错
这个时候从IIS启动应用,如果没做日志输出的话,是看不到日志的,需要直接到文件夹启动exe(Windows是这样操作,其他系统同理),这个时候运行就能看到错误提示


提示或许都是大同小异,反正就是说表有问题
然后我一张一张表倒查结构,发现结构完全一致,就更不明所以
最后定位到了__efmigrationshistory 表,把开发环境的这张表的内容原原本本地复制到了测试环境,再重启一次应用,搞定
缘落

具体原因没找到详细说明的文档,但是简单猜测一下:
可能是因为codefirst的应用在启动的时候,会根据数据__efmigrationshistory表的内容来检查数据库的表,如果不一致,就会报错退出
以上
2021.11.11
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表