小编Sve*_*ven的帖子

使用 Windows 身份验证的 ASP.NET Core 标识

我正在使用 .NET Core 3.0 Preview6。
我们有一个启用了 Windows 身份验证的 Intranet 应用程序,这意味着只允许有效的 AD 用户使用该应用程序。
但是,我们喜欢使用 ASP.NET Identity 运行我们自己的身份验证后端,因为它“开箱即用”。我刚刚使用用户的 Windows 登录向 AspNetUsers 表添加了一列。

我想要完成的是 Windows 用户使用他们的 Windows 登录名自动登录到应用程序。
我已经创建了一个自定义身份验证中间件,请参阅下面的代码:

public class AutoLoginMiddleware
{
    private readonly RequestDelegate _next;
    private readonly ILogger _logger;

    public AutoLoginMiddleware(RequestDelegate next, ILogger<AutoLoginMiddleware> logger)
    {
        _next = next;
        _logger = logger;
    }

    public async Task InvokeAsync(HttpContext context, UserService userService, UserManager<IntranetUser> userManager, 
        SignInManager<IntranetUser> signInManager)
    {
        if (signInManager.IsSignedIn(context.User))
        {
            _logger.LogInformation("User already signed in");
        }
        else
        {
            if (context.User.Identity as WindowsIdentity != null)
            { …
Run Code Online (Sandbox Code Playgroud)

c# windows-authentication asp.net-core asp.net-core-identity

15
推荐指数
1
解决办法
3798
查看次数

ASP.NET Core 2.0中RequiredAttribute的本地化

我在新的.NET Core项目中苦苦挣扎.我有2个项目:

  • 具有模型和数据注释的DataAccess项目(例如RequiredAttribute)
  • 具有MVC视图等的Web项目

我希望在一个地方全局本地化所有验证属性,以获得类似MVC 5的行为.这可能吗?

我不想为模型/视图等提供单独的语言文件.

使用SharedResources.resx文件和本地化的DataAnnotation消息时,Microsofts文档不是很清楚.

在MVC 5中我没有处理它.我只需要将语言环境设置为我的语言,一切都很好.

我尝试将ErrorMessageResourceName和ErrorMessageResourceType设置为DataAccess项目中的共享资源文件名"Strings.resx"和"Strings.de.resx":

[Required(ErrorMessageResourceName = "RequiredAttribute_ValidationError", ErrorMessageResourceType = typeof(Strings))]
Run Code Online (Sandbox Code Playgroud)

我还尝试将设置名称设为RequiredAttribute_ValidationError - 但它不起作用.

我已经.AddDataAnnotationsLocalization()在Startup.cs中添加了 - 但似乎什么也没做.

我读过几篇文章,但我找不到它为什么不起作用的原因.

编辑:我到目前为止:

1.)LocService类

 public class LocService
    {
        private readonly IStringLocalizer _localizer;

        public LocService(IStringLocalizerFactory factory)
        {
            _localizer = factory.Create(typeof(Strings));
        }

        public LocalizedString GetLocalizedHtmlString(string key)
        {
            return _localizer[key];
        }
    }
Run Code Online (Sandbox Code Playgroud)

2.)使用Strings.cs添加了文件夹"Resources"(带有虚拟构造函数的空类)

3.)添加了一个带有"RequiredAttribute_ValidationError"项的Strings.de-DE.resx文件

4.)修改了我的Startup.cs

public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient<MessageService>();
            services.AddDbContext<DataContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddSingleton<LocService>();
            services.AddLocalization(options => options.ResourcesPath = "Resources");
            services.AddMvc()
                .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver())
                .AddDataAnnotationsLocalization( …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core

6
推荐指数
3
解决办法
6984
查看次数

如何在Blazor中实现拖放?

我知道Blazor是一项新技术。当前版本为v0.5.1

但是,我目前正在为新的Web应用程序实施PoC。我们希望在应用程序中具有拖放功能。我尝试以Blazor方式实施它,但是它不起作用。

我的放置目标:

<div class="col" ondragstart="@AllowDragOver" ondrop="@Add">
Run Code Online (Sandbox Code Playgroud)

和可拖动的项目:

<span class="badge badge-warning" draggable="true">îtem 1</span>
Run Code Online (Sandbox Code Playgroud)

Blazor C#代码:

@functions {

void Add()
{
     Items.Add("hello");
}

void AllowDragOver(UIDragEventArgs e)
{
}
Run Code Online (Sandbox Code Playgroud)

}

问题是放置目标没有在浏览器中显示为放置目标:

在浏览器中拖放

到目前为止,我已经读到的是,将事件处理程序附加到Blazor C#函数(例如ondragstart)时,默认行为是众所周知的“ e.preventDefault()”,它应使放置目标可放置。

有谁知道如何解决这一问题?

斯文

html c# blazor

4
推荐指数
1
解决办法
2380
查看次数

忽略 Swagger 中的第 3 方控制器操作

我有一个 ASP.NET Core 2.1 Web 应用程序,它通过 Web API 接口提供 DevExpress 报告。

我想使用 swagger 来向消费者展示使用情况并提供一些有关我的 Web API 的有用信息。但是,Swagger 因以下错误而崩溃:

NotSupportedException:操作的模糊 HTTP 方法 - DevExpress.AspNetCore.Reporting.QueryBuilder.QueryBuilderController.Invoke (DevExpress.AspNetCore.Reporting.v18.2)。操作需要 Swagger 2.0 的显式 HttpMethod 绑定

问题在于 Swagger 试图分析 DevExpress 的QueryBuilderController 中包含的 API 。但是,我不想大摇大摆地分析这些 3rd 方控制器。我现在的问题是如何在 swagger 中过滤/禁用 3rd 方库?

谢谢斯文

swagger swagger-2.0 asp.net-core

3
推荐指数
1
解决办法
865
查看次数

MS Access 2003中的奇怪UPDATE语法

我有一个带有更新查询的Access应用程序,其语法如下:

UPDATE TABLE1, TABLE2 SET 
TABLE2.VALUE1 = TABLE1.VALUE1, 
TABLE2.VALUE2 = TABLE1.VALUE2, 
TABLE2.VALUE3 = TABLE1.VALUE3, 
TABLE2.VALUE4 = TABLE1.VALUE4
Run Code Online (Sandbox Code Playgroud)

查询正在运行,但我不明白这里发生了什么.我正在尝试将此查询转换为SQL Server.有人可以解释这个查询的作用吗?我的猜测是它是一种特殊的Access语法.

谢谢,斯文

sql ms-access vba

0
推荐指数
1
解决办法
737
查看次数