标签: coreclr

CoreCLR中的Type.GetCustomAttributes方法在哪里?

我试图从类中获取属性,似乎没有GetCustomAttributes方法.如何在CoreCLR中获取属性?

using System.Reflection;

class FooBar {
    FooBar() {
        GetType().GetCustomAttributes(); // does not compile
        GetType().GetField("test").GetCustomAttributes(); // compiles
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# reflection coreclr asp.net-core

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

coreclr的哪个版本?

在.NET CLI中,我可以使用该开关--version来获取CLI的版本.是否有类似的方式来获得该版本coreclr

.net coreclr asp.net-core

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

在asp.net core rc2中指定代理

我正在尝试使用dotnet核心应用程序中的WebAPI为请求指定Web代理.当我定位实际的clr(dnx46)时,这段代码曾经工作但是,现在我正在尝试使用rc2的东西,说支持的框架是netcoreapp1.0和netstandard1.5.

var clientHandler = new HttpClientHandler{
    Proxy = string.IsNullOrWhiteSpace(this._clientSettings.ProxyUrl) ? null : new WebProxy (this._clientSettings.ProxyUrl, this._clientSettings.BypassProxyOnLocal),
    UseProxy = !string.IsNullOrWhiteSpace(this._clientSettings.ProxyUrl)
};
Run Code Online (Sandbox Code Playgroud)

我想知道WebProxy类去了哪里.我无法在任何地方找到它,甚至在github存储库中也找不到它.如果它从WebProxy改变了,它改变了什么?我需要能够将代理设置为特定请求的特定URL,因此使用"全局Internet Explorer"方式不能满足我的需求.这主要用于调试Web请求/响应目的.

asp.net-web-api dotnet-httpclient coreclr asp.net-core

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

为什么 ASP.NET Core 在 User.Claims 属性中添加两次声明?

我有 asp.net core 应用程序,该应用程序正在使用 IdentityServer3 使用 OpenIdConnect 身份验证。当用户成功通过身份验证后,应用程序会从身份服务器收到正确的声明。我可以调试线路TokenValidatedContext.Ticket.Principal.ClaimsOnTokenValidatd确保应用程序收到所有声明。

代码片段

    var connectOptions = new OpenIdConnectOptions()
        {
            AutomaticAuthenticate = true,
            AutomaticChallenge = true,
            Authority = authority,
            ClientId = clientId,
            ResponseType = IdentityConstant.IdTokenClaim,
            AuthenticationScheme = IdentityConstant.OpenIdAuthenticationScheme,
            SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme,
            PostLogoutRedirectUri = postlogoutRedirectUri,
            CallbackPath = IdentityConstant.CallbackPath,
            Events = new OpenIdConnectEvents()
            {
                OnTokenValidated = async context =>
                {
                    var claims = context.Ticket.Principal.Claims;
                    await Task.FromResult(0);
                }
            }
        };
Run Code Online (Sandbox Code Playgroud)

下面是处理程序 TokenValidatedContext.Ticket.Principal.Claims中的快速观看OnTokenValidated

在此输入图像描述

但是,在家庭控制器中调试成功进行身份验证后User.Cliams,我看到所有声明都添加了两次。下面是Home控制器
的快速观看User.Claims

在此输入图像描述

为什么声明在 User.Claims 中添加两次?

asp.net-core-mvc coreclr identityserver3 asp.net-core

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

如何在asp.net core中缩小文件?

asp.net core 的文档展示了如何使用 grunt 或 gulp 进行捆绑和缩小 css文件js。但是,当我使用 vs 2015 创建项目时,它将bundleconfig.json文件添加到项目中。我想缩小 wwwroot/js 文件夹中的所有 js 文件。所以我更新了bundleconfig.json中的现有行以使用通配符*

{
    "outputFileName": "wwwroot/js/*.min.js",
    "inputFiles": [
      "wwwroot/js/*.js"
    ],
    // Optionally specify minification options
    "minify": {
      "enabled": true,
      "renameLocals": true
    },
    // Optinally generate .map file
    "sourceMap": false
  }
Run Code Online (Sandbox Code Playgroud)

但是当我发布项目时出现错误

处理 wwwroot/js/*.min.js 路径中的非法字符。参数名称:路径

minify asp.net-core-mvc coreclr asp.net-core

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

ServiceProvider 无法解析配置方法中的选项

我有asp.net 核心应用程序。我已经Options存储在 appsettings.json 文件中。我注册了Options服务,然后尝试在 Configure 方法中解决它。

但是服务提供商无法解析配置方法中的选项。

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
         services.Configure<HstsOptions>(Configuration.GetSection("HstsOptions"));
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime,IServiceProvider services)
    { 

            var options = services.GetService<HstsOptions>();
            // service provider cannot resolve options here, it returns null
            app.UseHsts(options);
    }

}
Run Code Online (Sandbox Code Playgroud)

coreclr asp.net-core

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

无法在asp.net核心中使用ajax将json发布到控制器

我有以下代码

控制器动作方法

    [HttpPost]
    public async Task<IActionResult> Approve(int[] ids)
    {
        await _service.Approve(ids).ConfigureAwait(false);
        return Json("Success.");
    }
Run Code Online (Sandbox Code Playgroud)

在客户端,我有以下发布数据

var data = JSON.stringify(getIDs())

   $.ajax({
        type: "POST",
        data: data,
        url: "approve",
        contentType: "application/json; charset=utf-8",
        processData: true,
        cache: false,
        })
        .done(function (response, textStatus, jqXHR) {
            // do something here
        })
        .fail(function (jqXHR, textStatus, errorThrown) {
            // do something here
        })

 function getIDs() {
        var keys = [];
         keys.push(1);
         keys.push(2);
         keys.push(3);
        return keys;
    }
Run Code Online (Sandbox Code Playgroud)

问题
在服务器上,在批准操作方法中,ids参数始终为空。

我也尝试将数据发送为

var data = JSON.stringify({ids:getIDs()})
Run Code Online (Sandbox Code Playgroud)

我将 ASP.NET Core 与目标框架 …

javascript jquery asp.net-core-mvc coreclr asp.net-core

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

在 .NET Core 2 中注册基于作用域的 HttpClient

我有 NET Core 2 Web API 应用程序。在此过程中,我必须调用客户端 A 的 API 来获取一些数据。所以我使用 HttpClient 来调用它。客户端 A 还要求我在标头中传递用户 ID 和密码。

因此,HttpClient我没有直接注入,而是对HttpClient如下内容进行了包装

public class ClientA : IClientA
{
    private readonly HttpClient _httpClient;

    public ClientA(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }

    public async Task<string> GetData()
    {
        return await _httpClient.HttpGetAsync("someurl");
    }
 }
Run Code Online (Sandbox Code Playgroud)

然后在 Service 中使用 ClientA

  public class MyService :IMyService
  {
      private readonly IClientA _clientA

      public MyService(IClientA clientA)
      {
           _clientA= clientA
      }

      public void DoSomethig()
      {
          _clientA.GetData();
      }           
  }
Run Code Online (Sandbox Code Playgroud)

然后我在 Startup.cs 中注册所有内容 …

.net-core coreclr asp.net-core asp.net-core-webapi asp.net-core-2.0

4
推荐指数
2
解决办法
5584
查看次数

如何构建 IOptions&lt;T&gt; 进行测试?

在 ASP.NET Core 2 中,我有以下类 IOptions<T>

public class MyOptions
{
    public string Option1 { get; set; }
    public string Option2 { get; set; }
}


public class MyService:IMyService
{
  private readonly MyOptions _options;
  public MyService(IOptions<MyOptions> options)
  {
    _options = options.Value;
  }
}
Run Code Online (Sandbox Code Playgroud)

appsettings.json

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  },  
  "MyOptions": {
    "Option1": "option 1 value",
    "Option2": "option 2 value"
  }
}
Run Code Online (Sandbox Code Playgroud)

然后我 startup.cs 我注册选项如下

services.Configure<MyOptions>(Configuration.GetSection("MyOptions"));
Run Code Online (Sandbox Code Playgroud)

dotnet 能够注入IOptions<MyOptions>MyService 类。

现在,我有集成测试项目。我已将相同的 appsettings.json 复制到集成测试项目中。我想创建IOptions<MyOptions>从 …

.net-core coreclr asp.net-core asp.net-core-2.0

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

.Core CLR VS Mono CLR 有什么区别?那么微软为什么要维护运行时环境呢?

.Core CLR VS Mono CLR 有什么区别?那么为什么微软要维护不同的运行时环境呢?

.net clr mono coreclr asp.net-core

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