小编Max*_*ini的帖子

npm ci 在 Windows 上使用 Angular 8 和 Node 12 输出错误:node-gyp重建

我的设置:

  • Windows 10
  • 适用于 Windows 的 NVM 1.1.7
  • 节点 12.14.1 和 npm 6.13.4
  • Angular 8.2.14 和 @angular/cli 8.3.22

只是尝试运行默认的角度模板:

> npm install -g @angular/cli # this installed the angular version mentioned above
> ng new test # Chose default options for the project
> cd test
> npm ci # lots of error messages
Run Code Online (Sandbox Code Playgroud)

最后一个命令会导致输出中出现很多错误(但不会使命令失败):

> fsevents@1.2.11 install C:\test\node_modules\@angular\compiler-cli\node_modules\fsevents
> node-gyp rebuild


C:\test\node_modules\@angular\compiler-cli\node_modules\fsevents>if not defined npm_config_node_gyp (node "C:\Users\foo\AppData\Roaming\nvm\v12.14.1\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Users\foo\AppData\Roaming\nvm\v12.14.1\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! find Python
gyp …
Run Code Online (Sandbox Code Playgroud)

node.js npm angular

14
推荐指数
1
解决办法
3005
查看次数

在Azure网站中启用Access-Control-Allow-Credentials标头(Azure App Services)

我们最近将一个API应用程序从Azure云服务迁移到Azure网站,一些客户端仍在使用我们的旧协议进行身份验证,该协议使用cookie(而不是通常的Authorization: BearerHTTP标头).我们需要支持此身份验证协议一段时间,因为客户端无法立即迁移.

为了支持针对API的跨源ajax请求中的cookie,客户端需要将设置withCredentials设置为trueXMLHttpRequest,并且服务器需要使用Access-Control-Allow-Credentials标头以及任何CORS请求进行响应.

我们面临的问题是Azure网站自己管理CORS,并使用自己的配置(限于允许的来源列表)作为响应,这不允许设置此标头...从而打破了申请我们所有的Ajax客户端!

有没有办法(临时)在响应中添加此标头?

ajax azure cors azure-web-sites

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

带有 System.Text.Json 的可选属性的自定义 JSON 序列化程序

我正在尝试实现一个 JSON 序列化机制,它处理nullJSON 值和丢失的 JSON 值,以便能够在需要时执行部分更新(这样当值丢失时它不会触及数据库中的字段,但它会在该值显式设置为null)。

我创建了一个从 RoslynOptional<T>类型复制的自定义结构:

public readonly struct Optional<T>
{
    public Optional(T value)
    {
        this.HasValue = true;
        this.Value = value;
    }

    public bool HasValue { get; }
    public T Value { get; }
    public static implicit operator Optional<T>(T value) => new Optional<T>(value);
    public override string ToString() => this.HasValue ? (this.Value?.ToString() ?? "null") : "unspecified";
}
Run Code Online (Sandbox Code Playgroud)

现在我希望能够对 JSON 进行序列化/反序列化,以便在通过Optional<T>对象往返时保留 JSON 中的任何缺失字段:

public class CustomType
{
    [JsonPropertyName("foo")]
    public Optional<int?> Foo { …
Run Code Online (Sandbox Code Playgroud)

c# json .net-core system.text.json

8
推荐指数
1
解决办法
5485
查看次数

如何在自定义UserChangeForm中覆盖用户名的django'unique'错误消息

我正在尝试覆盖默认的"具有该用户名的用户已存在".在我的自定义UserChangeForm表单中输入现有用户名时显示的错误消息.使用的Django版本:1.6.1

这是我的代码:

class CustomUserChangeForm(forms.ModelForm):
    username = forms.RegexField(
        label="User name", max_length=30, regex=r"^[\w.@+-]+$",
        error_messages={
            'invalid': ("My message for invalid"),
            'unique': ("My message for unique") # <- THIS
        }
    )

    class Meta:
        model = get_user_model()
        fields = ('username', 'first_name', 'last_name', 'email',)
Run Code Online (Sandbox Code Playgroud)

但是,如果我使用此代码输入现有用户名,我仍然会获得默认"具有该用户名的用户已存在".信息.请注意,输入错误的用户名(包含无效字符)时会显示自定义"我的无效邮件".

python django django-forms

7
推荐指数
2
解决办法
5253
查看次数

使用ASP.Net Web Api 2中的PUT动词上传文件

我想使用HTTP PUT动词公开ASP.Net Web Api 2动作来上传文件.这与我们的REST模型一致,因为API代表一个远程文件系统(类似于WebDAV,但实际上是简化的),因此客户端选择资源名称(因此PUT是理想的,POST不是一个合理的选择).

Web Api文档描述了如何使用multipart/form-data表单上载文件,但没有描述如何使用PUT方法进行上传.

您将使用什么来测试这样的API(HTML多部分表单不允许PUT动词)?服务器实现是否类似于web api文档中描述的多部分实现(使用MultipartStreamProvider),或者应该如下所示:

[HttpPut]
public async Task<HttpResponseMessage> PutFile(string resourcePath)
{
    Stream fileContent = await this.Request.Content.ReadAsStreamAsync();
    bool isNew = await this._storageManager.UploadFile(resourcePath, fileContent);
    if (isNew)
    {
        return this.Request.CreateResponse(HttpStatusCode.Created);
    }
    else
    {
        return this.Request.CreateResponse(HttpStatusCode.OK);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# file-upload http asp.net-web-api asp.net-web-api2

7
推荐指数
1
解决办法
9744
查看次数

ASP.NET Web API应用程序为启用了TransferRequestHandler的非存在路由返回HTTP 500

我创建了一个简单的Web API应用程序(Visual Studio中的空模板,启用了Web API),添加了一个控制器:

[RoutePrefix("api/test")]
public class TestController : ApiController
{
    [HttpGet]
    [Route(@"resource/{*path?}")]
    public async Task<HttpResponseMessage> GetFolder(string path = "")
    {
        return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = "OK" });
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我们需要file.pdfpath变量中支持文件扩展名(例如),所以我修改了web.config:

<system.webServer>
  <handlers>
    <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
    <remove name="OPTIONSVerbHandler" />
    <remove name="TRACEVerbHandler" />
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

    <!-- API must handle all file names -->
    <add name="ApiUrlHandler" path="/api/test/*" verb="GET,POST,PUT,DELETE,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

  </handlers>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

现在的问题是HTTP状态代码是不一致的,具体取决于前缀后提供的URL段/api/test/:

GET /api/test/resource => HTTP 200 (as …
Run Code Online (Sandbox Code Playgroud)

c# asp.net iis asp.net-web-api

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

状态码不成功时无法读取HttpResponseMessage内容

我有一个使用 SMS REST API 的服务HttpClient

HttpClient http = this._httpClientFactory.CreateClient();
// Skipped: setup HttpRequestMessage
using (HttpResponseMessage response = await http.SendAsync(request))
{
    try
    {
        _ = response.EnsureSuccessStatusCode();
    }
    catch (HttpRequestException)
    {
        string responseString = await response.Content.ReadAsStringAsync(); // Fails with ObjectDisposedException
        this._logger.LogInformation(
            "Received invalid HTTP response status '{0}' from SMS API. Response content was {1}.",
            (int)response.StatusCode,
            responseString
        );
        throw;
    }
}
Run Code Online (Sandbox Code Playgroud)

API 返回错误,但我希望能够记录它。因此,我需要记录失败的状态代码(我可以从中读取response.StatusCode)和相关内容(其中可能包含其他有用的错误详细信息)。

此代码在await response.Content.ReadAsStringAsync()此异常的指令上失败:

System.ObjectDisposedException:无法访问已处理的对象。
对象名称:'System.Net.Http.HttpConnection+HttpConnectionResponseContent'。
    模块“System.Net.Http.HttpContent”,在 CheckDisposed
    模块“System.Net.Http.HttpContent”,在 ReadAsStringAsync

一些消息来源建议,当状态码不在成功范围(200-299)内时,您不应读取响应内容,但如果响应确实包含有用的错误详细信息呢?

使用的 .NET 版本:AWS lambda linux …

c# dotnet-httpclient .net-core

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

在AngularJS中,如何在初始化所有控制器后运行代码?

我有一个由多个模块组成的单页AngularJS应用程序,其目的是为用户提供协作板(主要小部件)和其他相关小部件(其他连接用户,pad元数据等).

我选择拆分应用程序如下:

  • 1个托管服务的模块,负责公开pad组件的初始化方法
  • N个模块托管自定义指令(及其控制器),对应于应用程序中的不同小部件
  • 1个模块负责收集参数和初始化pad组件

让我们通过假设我只有一个小部件来简化这一点,小部件的唯一目标是向用户显示状态消息:"authenticating","authenticated","error"或"ready".

我选择在服务中使用订阅/通知模式,以通知窗口小部件共享组件状态的更改.

服务:

angular.module("app.core").factory("padService", padService);
function padService() {
    // Callback registration and notification code omitted
    return {
        initialize: function (authToken) { ... },
        onAuthenticated: function (callback) { ... },
        onReady: function (callback) { ... },
        onError: function (callback) { ... }
    };
}
Run Code Online (Sandbox Code Playgroud)

小部件:

angular.module("app.widget").directive("widget", widget);
function widget() {
    return {
        templateUrl: 'app/widget.html',
        restrict: 'E',
        controller: widgetController
    };
}
function widgetController($scope, padService) {
    $scope.message = "authenticating";
    padService.onAuthenticated(function (user) {
        $scope.message = "authenticated";
        // Do other …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

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

如何在Azure应用服务中管理(非SSL)证书?

我们希望将ASP.NET MVC应用程序从Azure Cloud Service切换到Azure App Service(Web应用程序).该应用程序当前正在使用WIF作为其身份框架,并且当它在服务器场配置中运行时,我们配置了一个SessionSecurityTokenHandler使用证书加密会话cookie 的自定义(因此,cookie可以由Web场的所有实例解密).

我们可以使用csdef/cscfg文件和与Cloud Service关联的内置Azure证书存储在Cloud Service方案中配置此证书,但Azure App Services没有这样的功能(除非我遗漏了一些内容).

有没有办法在App Service中配置证书?我们是否应该回退到另一种加密会话cookie的机制,例如共享机器密钥?机器密钥不是理想的解决方案,因为它迫使我们将某些配置从源代码控制中移除以避免泄漏密钥.

asp.net azure wif azure-web-sites

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

基于类的装饰器和repr()保护

我试图让我的基于类的装饰器保持repr()原始包装函数的行为(以匹配functools.wraps装饰器在函数上的工作方式).我正在使用python 3.3.

首先我尝试了functools:

import functools

class ClassBasedDecorator():
    def __init__(self, fn):
        self.fn = fn
        functools.update_wrapper(self, fn)
    def __call__(self, *args, **kwargs):
        self.fn(*args, **kwargs)

@ClassBasedDecorator
def wrapped(text):
    pass
Run Code Online (Sandbox Code Playgroud)

但是当我调用repr()装饰函数时,我得到:

>>> repr(wrapped)
'<__main__.ClassBasedDecorator object at 0x2d8860b6850>'
Run Code Online (Sandbox Code Playgroud)

很好,所以我试着自定义__repr__我的装饰器的方法,它应该被调用repr().

再次使用functools:

class ClassBasedDecorator():
    def __init__(self, fn):
        self.fn = fn
        functools.update_wrapper(
            self, fn,
            assigned=functools.WRAPPER_ASSIGNMENTS + ('__repr__',)
        )
    def __call__(self, *args, **kwargs):
        self.fn(*args, **kwargs)
Run Code Online (Sandbox Code Playgroud)

不会改变输出,但会发生一些有趣的事情:

>>> repr(wrapped)
'<__main__.ClassBasedDecorator object at 0x2d8860b69d0>'
>>> wrapped.__repr__()
'<function wrapped at 0x2d8860a9710>'
Run Code Online (Sandbox Code Playgroud)

显式设置__repr__ …

python repr decorator python-3.x python-decorators

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