我有一个Booking类,它有一个预订联系人(a Person)和一组导航属性(People),它们通过连接表链接到另一组导航属性(Bookings)Person.如何Booking为预订联系人关系启用级联删除生成表格?当我将它从流畅的API代码中删除时(启用了级联删除的默认设置),我从迁移中收到以下错误消息:
在'BookingPeople'表上引入FOREIGN KEY约束'FK_dbo.BookingPeople_dbo.People_PersonID'可能会导致循环或多个级联路径.指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他FOREIGN KEY约束.
无法创建约束或索引.查看以前的错误.
modelBuilder.Entity<Person>()
.HasMany<Booking>(s => s.aBookings)
.WithRequired(s => s.Contact)
.HasForeignKey(s => s.ContactId);
modelBuilder.Entity<Booking>()
.HasMany(t => t.People)
.WithMany(t => t.Bookings)
.Map(m => {
m.ToTable("BookingPeople");
m.MapLeftKey("BookingID");
m.MapRightKey("PersonID");
});
Run Code Online (Sandbox Code Playgroud) 我有一个 Azure 资源组,其中两个应用服务 Web 应用程序部署在不同的位置并按预期工作。我也有一个 Front Door 配置设置。通过azurefd.net地址访问时,这是按预期响应的。
我想向此配置添加自定义域。首先,我CNAME在我的 DNS 中创建了一个www地址。
然后我添加了一个简单的自定义域配置(通过 ARM 模板),将完全限定的自定义域名作为参数传递。
通过模板部署时,前端部分如下所示:
"frontendEndpoints": [
{
"name": "frontendEndpoint1",
"properties": {
"hostName": "[concat(parameters('frontDoorName'), '.azurefd.net')]",
"sessionAffinityEnabledState": "Enabled",
"sessionAffinityTtlSeconds": 0
}
},
{
"name": "frontendEndpoint2",
"properties": {
"hostName": "[parameters('customDomainName')]",
"sessionAffinityEnabledState": "Enabled",
"sessionAffinityTtlSeconds": 0
}
}
],
Run Code Online (Sandbox Code Playgroud)
前端按预期部署,我仍然可以访问该azurefd.net地址。
但是,当我尝试访问该www地址时,我在浏览器中收到一条错误消息:
我们的服务目前不可用。我们正在努力尽快恢复所有服务。请尽快回来查看。0tEdHXAAAAAADUxvBayGtQLDTjRthnz9XTE9OMjFFREdFMDMyMQBFZGdl
我已经等了半个多小时才能推出任何 DNS 更改,但它仍然不起作用。
可能是什么问题?排除此类错误的简单方法是什么?需要明确的是,我还没有在这个配置中添加任何 HTTPS 证书。Web 应用程序确实响应 HTTP 和 HTTPS,所以希望这不是问题。
As per Authentication and authorization for SPAs, I have created a new SPA with support for API authorization. You can view this on GitHub.
In order to support integration tests, I have added a new client (see appsettings.json) that is allowed the resource owner password grant type:
"SecureSpa.IntegrationTests": {
"Profile": "IdentityServerSPA",
"AllowedGrantTypes": [ "password" ],
"ClientSecrets": [ { "Value": "K7gNU3sdo+OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols=" } ],
"AllowedScopes": [ "SecureSpaAPI", "openid", "profile" ]
}
Run Code Online (Sandbox Code Playgroud)
Then within WeatherForecastControllerTests.cs, I attempt to request …
asp.net-core identityserver4 asp.net-core-identity asp.net-core-3.0
我有一个客户端 Blazor 应用程序。我想appsetting.json为我的客户端配置创建一个文件,就像我们environment.ts在 Angular 中有一个文件一样。
为此,我在其中保留了一个ConfigFiles文件夹wwwroot和一个 JSON 文件。我正在尝试阅读此文件,如下所示。
首先获取路径:
public static class ConfigFiles
{
public static string GetPath(string fileName)
{
return Path.Combine("ConfigFiles", fileName);
}
}
Run Code Online (Sandbox Code Playgroud)
比阅读它:
public string GetBaseUrl()
{
string T = string.Empty;
try
{
T = File.ReadAllText(ConfigFiles.GetPath("appsettings.json"));
}
catch (Exception ex)
{
T = ex.Message;
}
return T;
}
Run Code Online (Sandbox Code Playgroud)
但我总是收到错误:
找不到路径“/ConfigFiles/appsettings.json”的一部分。
在GetPath()方法里面,我也试过:
return Path.Combine("wwwroot/ConfigFiles", fileName);
Run Code Online (Sandbox Code Playgroud)
但我仍然得到同样的错误:
找不到路径“wwwroot/ConfigFiles/appsettings.json”的一部分。
由于IHostingEnvironment在客户端 Blazor 中没有概念,那么这里读取静态 JSON 文件的正确方法是什么?
asp.net-core blazor asp.net-core-3.0 .net-core-3.0 blazor-client-side
是否可以在没有 ASP.NET Core Web 应用程序项目的独立 .NET Standard 项目中使用依赖项注入?
由于没有startup.cs文件,我很想知道这是否可能,以及如何做到这一点?
如何配置 BlazorHub 端点以要求经过身份验证的用户在未经过身份验证的情况下自动重定向登录?
我已尝试配置默认授权策略以及调用RequireAuthenticatedBlazorHub 端点生成器,但当我运行 Blazor 应用程序时,我仍然没有重定向到登录页面。
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(); // added by me
services.AddAuthorization(options =>
{
options.DefaultPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
}); // added by me
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 …Run Code Online (Sandbox Code Playgroud) c# authentication blazor blazor-server-side asp.net-core-5.0
我是 ASP.NET Core 网页设计的初学者。我编写了一个视图组件,该组件具有一个表单,其中包含一些与视图模型相关的输入。这些输入之一是文件输入(IFormFile数据类型)。
我想将此视图模型提交给控制器的操作(POST操作),检查模型的有效性,如果模型状态有效,则返回另一个视图组件,如果模型状态无效,则使用此视图模型保留在该视图组件上。
这是我的视图模型:PricingViewModel.cs
public class PricingViewModel
{
[Display(Name = "Select a file")]
public IFormFile formFile { get; set; }
[Display(Name = "ColumnCode")]
[Required(ErrorMessage = "Enter {0} value, please")]
public string colCode { get; set; }
[Display(Name = "ColumnName")]
[Required(ErrorMessage = "Enter {0} value, please")]
public string colName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的视图组件(控制器):PricingComponent.cs
public class PricingComponent : ViewComponent
{
public async Task<IViewComponentResult> InvokeAsync(PricingViewModel pricing)
{
return await Task.FromResult((IViewComponentResult)View("PricingView", pricing));
}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个ViewComponent可以与 TagHelpers 一起使用的对象,其中我传入一个对象作为参数。
例如,我有这个ViewComponent\xe2\x80\x94 最终可能会有更多参数:
public IViewComponentResult Invoke(string? pageTitle, string? description, string? headerView)\nRun Code Online (Sandbox Code Playgroud)\n\n我想做一些类似的事情:
\n\npublic class PageHeaderViewComponentOptions \n{\n public string pageTitle2;\n public string Description;\n}\n\npublic IViewComponentResult Invoke(PageHeaderViewComponentOptions phvc)\nRun Code Online (Sandbox Code Playgroud)\n\n并像这样使用它:
\n\n<vc:page-header phvc:page-title2="Test Title"></vc:page-header>\nRun Code Online (Sandbox Code Playgroud)\n\n但是,这不起作用。
\n\n我还尝试显式设置参数类的属性信息,如下所示:
\n\n[HtmlTargetElement("PageHeaderViewController")]\npublic class PageHeaderViewComponentOptions\n{\n [HtmlAttributeName("page-title")]\n public string pageTitle2 { get; set; }\n public string Description;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n也没有运气。
\n\n我的想法是我可以将该对象直接传递给视图。键入此内容,我想知道单独传递参数然后将每个参数分配给特定视图模型的成员是否是一个更好的主意。
\n\n任何帮助将不胜感激。
\nasp.net-core asp.net-core-tag-helpers c#-8.0 asp.net-core-viewcomponent asp.net-core-3.0
我想创建一个单元测试以确保方法使用 xUnit 和 Moq 记录错误。此代码适用于 ASP.NET Core 2.1:
//Arrange
var logger = new Mock<ILogger<MyMiddleware>>();
var httpContext = new DefaultHttpContext();
var middleware = new MyMiddleware(request => Task.FromResult(httpContext), logger.Object);
//Act
await middleware.InvokeAsync(httpContext);
//Assert
logger.Verify(x => x.Log(LogLevel.Error, It.IsAny<EventId>(), It.IsAny<FormattedLogValues>(), It.IsAny<Exception>(), It.IsAny<Func<object, Exception, string>>()), Times.Once);
Run Code Online (Sandbox Code Playgroud)
为了验证_logger.LogError("Error message");在middleware.InvokeAsync.
但是,在 ASP.NET Core 3.0 中,我无法验证是否正在调用记录器。Microsoft.Extensions.Logging.Internal不能再引用,所以FormattedLogValues不可用。
我尝试更改Assert()to useobject而不是FormattedLogValues,而且IReadOnlyList<KeyValuePair<string, object>>因为那FormattedLogValues是基于(FormattedLogValues.cs)。
这是我在 Visual Studio 测试运行程序中收到的错误消息:
Message:
Moq.MockException :
Expected invocation …Run Code Online (Sandbox Code Playgroud) 我正在尝试新的可为空引用类型 C# 8.0。我遇到了一个小问题:
foreach(FileSystemAccessRule rule in directorySecurity.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
{
// do something with rule
}
Run Code Online (Sandbox Code Playgroud)
这显示了一个警告,因为编译器认为rule 可能是null,而它永远不会是。
我目前的修复是这样的:
foreach(FileSystemAccessRule? rule in directorySecurity.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
{
if (rule == null) continue;
// do something with rule
}
Run Code Online (Sandbox Code Playgroud)
但我会更高兴修复,像[NeverNull]FileSystemAccessRule rule或类似的东西。有没有办法实现这一目标?
asp.net-core ×6
c# ×5
blazor ×2
c#-8.0 ×2
.net-core ×1
ajax ×1
dns ×1
javascript ×1
moq ×1
nullable ×1
sql-server ×1
xunit.net ×1