在部署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不再流行了,因为它正被弃用.

Asp.net相关问答推荐

DataTables-如何修改来自JSON响应或其他DataTables参数的无结果(ZeroRecords)消息

在这个 For 循环计数没有增加

.net 中的 [] 括号是什么?

MSCharts找不到请求类型'GET'的http处理程序错误

ASP.NET:获取自 1970 年 1 月 1 日以来的毫秒数

获取在 asp.net identity 2.0 中分配了角色的用户列表

将复选框的值传递给 asp.net mvc4 中的控制器操作

Web Api 请求内容在操作过滤器中为空

MvcBuildViews true 与 ASP.NET MVC 2 中的实体框架

新的 ASP.NET MVC 5 应用程序如何知道如何创建数据库以及帐户控制器如何访问数据库?

在 ASP.NET 中将虚拟路径转换为实际 Web 路径

IIS 10 上的 ASP.NET Core 404 错误

ASP.NET 会话超时测试

如何判断用户代理是 ipad 还是 iphone?

如何获得 System.Diagnostics.Process 的输出?

通过 CultureInfo 格式化字符串

在 Visual Studio 2013 中更改项目端口号

Sys.WebForms.PageRequestManagerServerErrorException:处理服务器上的请求时发生未知错误.

Request.UserHostAddress 和 Request.ServerVariables["REMOTE_ADDR"].ToString() 有什么区别

如何识别字符串是否包含 unicode 字符?