小编Muh*_*eed的帖子

在ASP.NET 5 MVC 6应用程序中使用Web API

我有一个包含自定义错误页面的ASP.NET 5 MVC 6应用程序.如果我现在想在/api路径下添加API控制器,我使用Map方法看到了以下模式:

public class Startup
{
    public void Configure(IApplicationBuilder application)
    {
        application.Map("/api", ConfigureApi);

        application.UseStatusCodePagesWithReExecute("/error/{0}");

        application.UseMvc();
    }

    private void ConfigureApi(IApplicationBuilder application)
    {
        app.Run(async (context) =>
        {
            await context.Response.WriteAsync("Hello World from API!");
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

上面的代码在/api路径下创建了一个全新的独立应用程序.这很棒,因为您不希望Web API有自定义错误页面,但确实希望它们适用于您的MVC应用程序.

我是否正确地认为在ConfigureApi中,我应该再次添加MVC以便我可以使用控制器?另外,如何针对此子应用程序专门配置服务,选项和过滤器?有没有办法ConfigureServices(IServiceCollection services)为这个子应用程序?

private void ConfigureApi(IApplicationBuilder app)
{
    application.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)

asp.net-web-api asp.net-core-mvc asp.net-core

6
推荐指数
1
解决办法
938
查看次数

如何使用 SwashBuckle 设置或删除默认响应内容类型

使用 SwashBuckle 时的默认响应内容类型是text/plain。如何将默认值更改为application/json甚至删除text/plain

asp.net-web-api swashbuckle

6
推荐指数
1
解决办法
9639
查看次数

什么是ASP.NET Core中的默认,系统和Mi​​crosoft LogLevel

默认项目模板在以下位置具有以下日志记录配置appSettings.json

"Logging": {
  "IncludeScopes": true,
  "LogLevel": 
    "Default": "Debug",
    "System": "Information",
    "Microsoft": "Information"
  }
}
Run Code Online (Sandbox Code Playgroud)

是什么DefaultSystemMicrosoft什么?

asp.net logging asp.net-core-mvc asp.net-core

6
推荐指数
1
解决办法
1648
查看次数

使用内容安全策略(CSP)的页面特定JavaScript

我想在整个网站上使用内容安全策略(CSP).这要求所有JavaScript都在单独的文件中.我共享了所有页面使用的JavaScript,但还有一些特定于页面的JavaScript,我只想为特定页面运行.处理页面特定JavaScript以获得最佳性能的最佳方法是什么?

我可以想到解决此问题的两种方法是使用特定于页面的JavaScript包或带有switch语句的单个JavaScript包来执行特定于页面的内容.

html javascript performance bundling-and-minification content-security-policy

6
推荐指数
1
解决办法
510
查看次数

如何使用 TypeScript 在 Vue.js 中使用提供/注入

我将 Vue.js 与 TypeScript 和vue-property-decorator包一起使用。根据文档,理论上我可以做这样的事情:

import { Component, Inject, Provide, Vue } from 'vue-property-decorator'

const s = Symbol('baz')

@Component
export class MyComponent extends Vue {
  @Provide() foo = 'foo'
  @Provide('bar') baz = 'bar'

  @Inject() foo: string
  @Inject('bar') bar: string
  @Inject(s) baz: string
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我想在一个不是组件的类上使用@Provide@Inject怎么办?例如,如果我有ComponentA那取决于ServiceA那取决于ServiceB. 我该如何设置?

typescript vue.js vue-component vuejs2

6
推荐指数
1
解决办法
9749
查看次数

使用 EF Core 插入 SQL Server 上的事务死锁

我正在尝试使用 Entity Framework Core 快速执行大量包含大量数据的单独插入。我将数据插入到几个相关的表中,偶尔会收到SqlException以下消息;

事务(进程 ID 120)在与另一个进程的锁资源上发生死锁,并已被选为死锁牺牲品。重新运行事务。

我正在做的唯一读取是作为插入的一部分来检索新创建记录的 ID。您可以从发生的插入中看到 Entity Framework Core 日志。如果它有所作为,我向 UniqueId 列添加了一个非聚集索引。

如何避免死锁并因此获得更好的性能?

2018-06-13 17:11:59 DBG Executing DbCommand [Parameters=["@p0='40515' (Nullable = true), @p1='22a98afd-57c9-4821-8027-db9a7d1098d0' (Nullable = true), @p2='2017-12-13T17:11:41.8202539+01:00' (Nullable = true), @p3='2018-06-13T16:11:57.3627370+00:00', @p4='11' (Nullable = true), @p5='0' (Nullable = true), @p6='Teacher Tech' (Nullable = false) (Size = 1000), @p7='3' (Nullable = true), @p8='True' (Nullable = true), @p9='7f72ce12-7c3a-449e-b456-97db816dd7e6' (Nullable = true), @p10='11.0.40515.3' (Size = 50), @p11='False' (Nullable = true), @p12='False' (Nullable = true), @p13='bridge 2015-12-09_15-29 97f149c' …
Run Code Online (Sandbox Code Playgroud)

sql-server deadlock transactions sql-insert entity-framework-core

6
推荐指数
1
解决办法
3010
查看次数

如何在Azure管道中获取Git标记

在Azure Pipelines中,我启用了git标签来触发管道,如下所示:

trigger:
  branches:
    include:
    - '*'
  tags:
    include:
    - '*'
Run Code Online (Sandbox Code Playgroud)

现在,我想知道是否有一种方法可以通过编程确定:

  1. 管道是从git commit还是git标签开始的?
  2. 如果管道是从git标签启动的,标签名称是什么?

git git-tag azure-devops azure-pipelines

6
推荐指数
4
解决办法
1869
查看次数

如何为所有用户静默安装 NSIS 可执行文件

我有一个 NSIS 安装程序可执行文件,我想为所有用户静默安装它。我知道我可以传递/S参数来进行静默安装。问题是安装程序的默认选项是仅为当前用户安装。如何从命令行更改此选项:

installer.exe /S
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

installation command-line windows-installer nsis silent-installer

5
推荐指数
2
解决办法
2万
查看次数

在 ASP.NET Core 中注册子 IOptions

我有以下配置设置:

public void ConfigureServices(IServiceCollection services)
{
    var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
    services.Configure<AppSettings>(configuration);
}

public class AppSettings
{
    public ChildSettings Child { get; set; }

    public string Property { get; set; }
}

public class ChildSettings
{
    public string ChildProperty { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我的 appSettings.json 如下所示:

{
    "Child": {
        "ChildProperty": "Value"
    }
    "Property": "Value"
}
Run Code Online (Sandbox Code Playgroud)

我可以IOptions<AppSettings>很好地注入我的控制器:

public class MyController : Controller
{
    public MyController(IOptions<AppSettings> options)
    {
        ChildSettings appSettings = options.Value;
    }
}
Run Code Online (Sandbox Code Playgroud)

它有点旧了,必须下降几个级别才能到达您想要的设置对象。有没有一种方法可以IOptions<ChildSettings>像这样使用:

public class …
Run Code Online (Sandbox Code Playgroud)

asp.net configuration asp.net-core-mvc asp.net-core

5
推荐指数
1
解决办法
2050
查看次数

如何阻止Azure IIS附加错误状态代码查询字符串

我在web.config文件中进行了以下设置来处理错误:

<httpErrors errorMode="Custom" existingResponse="Replace">
  <remove statusCode="500" />
  <error statusCode="500" responseMode="ExecuteURL" path="/error/internalservererror/" />
</httpErrors>
Run Code Online (Sandbox Code Playgroud)

当我在我的应用程序中抛出异常时,它在本地工作正常,但它重定向到azure中错误页面中的以下URL(请注意,我抛出异常的页面位于URL的末尾:

https://example.com/error/internalservererror/?500;https://example.com/error/internalservererror/?500;https://example.com/error/internalservererror/?500;https://example的.com /错误/ internalservererror/500; HTTPS:?//example.com/error/internalservererror/ 500; HTTPS:?//example.com/error/internalservererror/ 500; HTTPS:?//example.com/error/ ?internalservererror/500; HTTPS://example.com/error/internalservererror/ 500; HTTPS:?//example.com/error/internalservererror/ 500; HTTPS:?//example.com/error/internalservererror/ 500; https://example.com/error/internalservererror/?500;https://example.com/error/internalservererror/?500;https://example.com/error/internalservererror/?500;https://example的.com /错误/ internalservererror/500; HTTPS:?//example.com/error/internalservererror/ 500; HTTPS:?//example.com/error/internalservererror/ 500; HTTPS:?//example.com/error/ ?internalservererror/500; HTTPS://example.com/error/internalservererror/ 500; HTTPS:?//example.com/error/internalservererror/ 500; HTTPS:?//example.com/error/inter ?nalservererror/500; HTTPS://example.com/error/internalservererror/ 500; HTTPS:?//example.com/about/

如何阻止IIS在Azure中检测此行为?

iis asp.net-mvc azure http-error azure-web-sites

5
推荐指数
1
解决办法
306
查看次数