小编phu*_*uzi的帖子

ASP NET Web API中的路由 - 适用于不同版本的API

我在阅读有关Attribute Routing in Web API 2这里

文章说,

Here are some other patterns that attribute routing makes easy.

API versioning

In this example, “/api/v1/products” would be routed to a different controller than “/api/v2/products”.

/api/v1/products
/api/v2/products
Run Code Online (Sandbox Code Playgroud)

怎么会?

编辑:我会在正常路由中执行此操作:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
         config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/v2/products",
            defaults: new { controller = V2_Products }
        );

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/v1/products",
            defaults: new { controller = V1_Products }
        );
    } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net routing asp.net-web-api asp.net-mvc-5

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

包装承诺JavaScript通用功能

如何在promise中包含一个可以同步/同步功能的函数?

我打电话给下面的功能

action[fn](req, res);
Run Code Online (Sandbox Code Playgroud)

在函数fn(在下面的例子中)运行可以有内部(我使用动态调用每个函数)同步 a-sync如下例所示,

  1. 它是如何建议将其包装在诺言中.
  2. 如果有的话如何处理错误......

我使用nodeJS应用程序

 run: function (req, res, filePath) {
        var writeStream = fs.createWriteStream(fileRelPath, {flags: 'w'});
        req.pipe(writeStream);
        req.on("end", function () {
            console.log("Finish to update data file")
        });
        res.end("File " + filePath + " saved successfully");
    }
Run Code Online (Sandbox Code Playgroud)

javascript node.js promise q bluebird

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

Chrome 扩展程序:内容安全策略错误

我正在开发可打开新窗口的 Chrome 扩展程序。该窗口包含我page.html的一些脚本,这就是问题所在,因为在控制台中我可以看到错误......现在。

当我不向我添加任何其他内容时,manifest.json或出现page.html此错误:

拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“script-src 'self' blob: filesystem: chrome-extension-resource:”。'unsafe-inline' 关键字、散列 ('sha256-t+n/+H6ALc8VWtFbu1Zd7/MPwtSjSk8PIrfccO7FJrg=') 或随机数 ('nonce-...') 需要启用内联执行。`,

如果我添加

 "content_security_policy": "script-src 'self' chrome-extension://capfbnhhhkfclmggnafjgkolommmmoch; object-src 'self';"
Run Code Online (Sandbox Code Playgroud)

到我的manifest.json,我得到

拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“script-src 'self' chrome-extension://capfbnhhhkfclmggnafjgkolommmmoch”。启用内联执行需要“unsafe-inline”关键字、哈希(“sha256-t+n/+H6ALc8VWtFbu1Zd7/MPwtSjSk8PIrfccO7FJrg=')或随机数(“nonce-...”)。

当我在我的meta标签中添加一些标签时,page.html出现了相同或类似的错误。

我的问题是:我该如何解决?因为我认为这"script-src 'self' blob: filesystem: chrome-extension-resource:"是某种模板,所以我必须在此之后添加一些数据:...但我真的不知道是哪个。我在这里看到一些关于它的东西,但我不知道我应该用它做什么或我应该在哪里写它。所以请帮助我,如果我修复了那个错误,我会很高兴。

窗口打开的代码:

$.get(chrome.extension.getURL('/page.html'), function(data) {
    var myWindow;
    myWindow = window.open("", "TopSerialy.sk Vyh?adáva?","width=386,height=290");
    myWindow.moveTo((screen.width/2)-(386/2), ((screen.height-93)/2)-(290/2));
    myWindow.document.write(data);
});
Run Code Online (Sandbox Code Playgroud)

page.html仅包含在按下按钮时关闭窗口的简单脚本,由<script>functions, etc...</script>HTML 中的标记声明,而不是<script scr="some_url/script.js"></script>!

html javascript google-chrome-extension

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

在 Visual Studio 16.9.0 Android“部署到设备”错误 - 命令太长

在我的 xamarin Android 项目中,一切正常,直到我更新到 Visual Studio 2019 v16.9.0。

升级后,我能够成功构建项目,但是如果我尝试部署或调试到设备或模拟器,我会收到以下错误:

[构建日志的最后一部分]

  Adding assembly reference for Xamarin.Firebase.Analytics.Impl, recursively...
  Adding assembly reference for Xamarin.Firebase.Common, recursively...
  Adding assembly reference for Xamarin.Firebase.Iid, recursively...
  Adding assembly reference for Xamarin.Firebase.Iid.Interop, recursively...
  Adding assembly reference for Xamarin.Firebase.Measurement.Connector, recursively...
  Adding assembly reference for Xamarin.Firebase.Messaging, recursively...
  Adding assembly reference for Xamarin.Forms.Core, recursively...
  Adding assembly reference for Xamarin.Forms.Platform.Android, recursively...
  Adding assembly reference for Xamarin.Forms.Platform, recursively...
  Adding assembly reference for Xamarin.Forms.Xaml, recursively...
  Adding assembly reference for Xamarin.Google.Android.Material, recursively...
  Adding assembly reference for …
Run Code Online (Sandbox Code Playgroud)

visual-studio-debugging xamarin.android xamarin xamarin.forms visual-studio-2019

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

尝试安装 NodeJS 14 后管道破裂

我正在尝试安装最新的nodejs pkg(14.17.x)。我收到错误:

dpkg-deb:错误:粘贴子进程被信号终止(管道损坏)。

现在,我无法执行更新和安装 pkg 命令,出现以下错误:

( dpkg-deb: 错误: 粘贴子进程被信号杀死(管道损坏) ; 尝试时 (( kali@kali:~$ sudo apt update
kali@kali:~$
kali@kali:~$ sudo apt full-upgrade -y
卡利@卡利:~$
)

dpkg:处理存档 /var/cache/apt/archives/nodejs_14.17.1-deb-1nodesource1_amd64.deb (--unpack)时出错:
尝试覆盖“/usr/share/doc/nodejs/api/punycode.md”,其中也在包nodejs-doc 12.21.0~dfsg-4
dpkg-deb中:错误:粘贴子进程被信号杀死(管道损坏)

你能帮我吗?

node.js

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

如何在 C# 中将 Json 对象转换为数组

我正在尝试将 JSON 对象转换为 C# 数组。

这是我从服务器 Web 请求响应获取的 JSon:

string result = sr.ReadToEnd(); // this line get me response 
result = {
    "subjects": [{
        "subject_id": 1,
        "subject_name": "test 1",
        "subject_class": 4,
        "subject_year": "2015",
        "subject_code": "t-1"
    },{
        "subject_id": 2,
        "subject_name": "test 2",
        "subject_class": 5,
        "subject_year": "",
        "subject_code": "t-2"
    }]
};

dynamic item = JsonConvert.DeserializeObject<object>(result);  

string iii = Convert.ToString(item["subjects"]);
Run Code Online (Sandbox Code Playgroud)

我想获取主题并将它们保存在数组中,以便我可以将它们用于其他目的。

我将这些用于方法,但总是得到空值。

List<subjects> subject1 = (List<subjects>)JsonConvert.DeserializeObject(iii, typeof(List<subjects>));
Run Code Online (Sandbox Code Playgroud)

subjects[] subject2 = JsonConvert.DeserializeObject<subjects[]>(iii);
Run Code Online (Sandbox Code Playgroud)

请帮我解决这个问题。

我的科目是..

class subjects
{
    public int id { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# arrays json

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

跨域匿名和使用凭证有什么区别

来自 MDN

匿名的

执行跨域请求(即,带有 Origin: HTTP 标头)。但是没有发送凭据(即,没有发送 cookie、没有 X.509 证书,也没有发送 HTTP 基本身份验证)。如果服务器没有向源站点提供凭据(通过不设置 Access-Control-Allow-Origin: HTTP 标头),图像将被污染并限制其使用。

使用凭证

发送使用凭证执行的跨域请求(即,使用 Origin: HTTP 标头)(即执行 cookie、证书和 HTTP 基本身份验证)。如果服务器没有向源站点提供凭据(通过 Access-Control-Allow-Credentials: HTTP 标头),图像将被污染并限制其使用。

但是,它们之间的用法区别是什么。

cors

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

将 appsettings.json 映射到 Dictionary&lt;string, Value&gt;

我有以下配置

"Options": {
  "Host": "123",
  "UserName": "test",
  "Password": "test",
  "Files": [
    {
      "Key": "asd",
      "Value": {
        "HostLocation": "asd",
        "RemoteLocation": "asd"
      }
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我试图将它绑定到以下对象

public class Options
{
    public string Host { get; set; }
    public string UserName { get; set; }
    public string Password { get; set; }
    public Dictionary<string, FileOptions> Files { get; set; }

    public class FileOptions
    {
        public string HostLocation { get; set; }
        public string RemoteLocation { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是当我尝试将文件绑定到字典时。他们不受束缚。我得到一个生成的值为 1 …

c# appsettings .net-core asp.net-core

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

.NET 6 MVC 启用 razor 运行时编译会破坏 program.cs

我按照https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-6.0&tabs=visual-studio上的简单步骤启用 cshtml 视图的运行时编译。

但是,一旦我将“.AddRazorRuntimeCompilation()”添加到构建器中:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages()
    .AddRazorRuntimeCompilation();
Run Code Online (Sandbox Code Playgroud)

这会导致项目运行时出错:

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");
Run Code Online (Sandbox Code Playgroud)
System.ArgumentNullException
  HResult=0x80004003
  Message=Value cannot be null. (Parameter 'source')
  Source=System.Linq
  StackTrace:
   at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Linq.Enumerable.OfType[TResult](IEnumerable source)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionDescriptorProvider..ctor(IEnumerable`1 pageRouteModelProviders, IOptions`1 mvcOptionsAccessor, IOptions`1 pagesOptionsAccessor)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc

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

.NET 6.0 Cannot modify ServiceCollection after application is built problem

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();


app.UseRouting();
builder.Services.AddControllersWithViews();
app.UseEndpoints(endpoints => endpoints.MapControllerRoute(
        name: "default",
        pattern : "{Controller}/{Action}"
    ));
app.Run();

Run Code Online (Sandbox Code Playgroud)

When I Write This Code Into Program.cs I Get An Error Like Title

c# asp.net-core-mvc .net-6.0

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