在部署ASP.NET Core应用程序到azure并打开该网站时,我发现以下错误:
InvalidOperationException:在上找不到"UserSecretsIdAttribute"
异常详细信息还包括错误发生在启动时.cs在这行代码中:
建设者AddUserSecrets();
谢谢
在部署ASP.NET Core应用程序到azure并打开该网站时,我发现以下错误:
InvalidOperationException:在上找不到"UserSecretsIdAttribute"
异常详细信息还包括错误发生在启动时.cs在这行代码中:
建设者AddUserSecrets();
谢谢
最近刚刚更新了用户机密模块.版本1.0.1和更高版本现在要求您为用户秘密的id指定程序集级属性,或者作为后备,就像以前在project.json中一样.
以下是GitHub上的公告:https://github.com/aspnet/Announcements/issues/209
您可以在中定义机密id.csproj是这样的:
<PropertyGroup>
<UserSecretsId>aspnet-TestApp-ce345b64-19cf-4972-b34f-d16f2e7976ed</UserSecretsId>
</PropertyGroup>
这将生成以下程序集级属性.或者,您当然也可以自己添加,例如添加到Startup.cs中,而不是将其添加到.csproj文件中:
[assembly: UserSecretsId("aspnet-TestApp-ce345b64-19cf-4972-b34f-d16f2e7976ed")]
此外,你应该使用:
builder.AddUserSecrets<Startup>();
它将在给定类型的程序集中搜索该属性,在本例中,我使用了Startup类.
Note: this will be deprecated in 2.0: (1.0.2 and 1.1.1 have marked it obsolete)
builder.AddUserSecrets();
我判断了source code的用户机密配置,在没有该类型的情况下调用AddUserSecrets()
可以执行以下操作:
var attribute = entryAssembly.GetCustomAttribute<UserSecretsIdAttribute>();
if (attribute != null)
{
return AddUserSecrets(configuration, attribute.UserSecretsId);
}
// try fallback to project.json for legacy support
try
{
var fileProvider = configuration.GetFileProvider();
return AddSecretsFile(configuration, PathHelper.GetSecretsPath(fileProvider));
}
catch
{ }
// Show the error about missing UserSecretIdAttribute instead an error about missing
// project.json as PJ is going away.
throw MissingAttributeException(entryAssembly);
它试图在程序集上找到UserSecretsId
属性,但失败了,判断它是否能在project中找到它.json.然后(如注释所示)返回一个关于缺少属性的错误,因为他们不想抱怨项目.json不再流行了,因为它正被弃用.