我在 Azure 中有一个应用服务,它作为我正在设计的系统的 API 运行。由于 API 负责直接访问数据库,我显然不想在源代码中存储连接字符串,因此将其存储在 Azure 仪表板上应用服务配置中的连接字符串部分。
我的代码几乎是这个 >> https://github.com/medhatelmasry/JwtAuthentication/blob/master/JwtAuthentication/Startup.cs 的副本,除了我检查了它正在运行的当前配置(调试,发布等),因此当我在 Visual Studio 中本地调试时,我使用的是 localdb 连接(硬编码)。我有一个 appsettings.json 文件,但其中没有连接字符串,只有 JWT 身份验证和日志记录的设置。
当这被调用时:
services.AddDbContext<ApplicationDbContext>(
option => option.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
Run Code Online (Sandbox Code Playgroud)
我在 Azure 中得到以下信息:
Unhandled Exception: System.ArgumentNullException: Value cannot be null
Parameter name: connectionString
Run Code Online (Sandbox Code Playgroud)
在过去的一周里,我一直在愚蠢地工作,试图让它发挥作用,并且一直在兜圈子,我快把自己逼疯了。Google 和 StackOverflow 的结果喜忧参半,因为多年来不同版本的 Azure 和 ASP.NET Core 给出了不同的答案。就好像它根本无法访问 Azure 配置。请参考上面的链接,因为这与我的设置相同,并且基于 .NET 版本和类型(核心或框架)有许多不同的答案。
编辑:请阅读我的问题,连接字符串未存储在项目的 appsettings.json 文件中,它存储在 Azure 中,如下所示(我已将连接字符串名称清空,但它们确实与代码中的内容匹配,不是不是“默认连接”):
c# azure azure-configuration azure-sql-database asp.net-core
我在 Blazor 服务器端应用程序中有以下代码:
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Email</th>
<th>Name</th>
</tr>
</thead>
<tbody>
@foreach (var applicationUser in ApplicationUsers)
{
string userId = applicationUser.Id;
Guid? personId = applicationUser.PersonId;
<tr>
<td>@applicationUser.Email</td>
<td>@applicationUser.PersonName</td>
@if (personId != null)
{
<td>
<button class="btn btn-block btn-primary" @onclick="() => ShowEditPersonDialog(personId)" style="color: rgb(255, 255, 255); background-color: rgb(49, 56, 215);" @type="button">Edit Person</button>
</td>
}
</tr>
}
</tbody>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
然而这个:
@onclick="() => ShowEditPersonDialog(personId)"
...不起作用。由于它在组件上方加载,直到第一行的第一个按钮(有 4 个用户 - 应加载 4 行),然后按钮无法正确呈现并引发未处理的异常:
我试过了:
@onclick="() => ShowEditPersonDialog(personId)" - 上面显示的异常@onclick="(e) => …我正在尝试查找 Azure Active Directory (AAD) 用户名的最大长度。用户名采用 UPN 格式(用户名@域),因此用户名和域字段大概有两个字符串长度限制。
我在网上能找到的只是标准 Windows 用户或 Windows 域用户的最大长度,即 20 个字符。蔚蓝是一样的吗?想必这只是用户名,那么域字符串的限制是多少?
我有一个非常令人困惑的问题,主要是因为我得到的异常非常无益且非描述性。
我有一个基于 ASP.Net Core 的 API,并且刚刚添加了一个新控制器。我正在使用 ASP.Net Core 3.0,并使用以下命令在 Startup.Configure 中映射我的控制器:
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
但是,在调试中运行 API 时,我在启动时遇到以下异常:
RoutePatternException:路由模板中存在不完整的参数。检查每个“{”字符是否都有匹配的“}”字符。
我删除了控制器,问题就消失了,所以我认为控制器有问题,导致端点映射抛出此异常,但我看不到它是什么?