小编Omt*_*guy的帖子

ASP.NET Web API比ASP.NET MVC有什么好处

我频繁地体验到Web API有一些限制和"ASP.NET MVC"中不存在的一些缺点.

例如,ASP.NET Web API不支持[OutputCache]属性"开箱即用",因此我必须安装NuGet插件才能支持它.

我的问题是,如果我可以选择ASP.NET MVC,为什么我应该选择ASP.NET Web API,据我所知,它可以做任何WEB API可以做的甚至更多?

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

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

WEBAPI ActionContext Request.Properties.Add 用于存储敏感信息

我想将信息从操作过滤器(数据库)传递到操作函数。

使用 ActionContext Request.Properties.Add 存储数据是否安全?

WEBAPI 客户端是否有可能看到该信息或其安全性,因为将信息存储在 Cache\Session 中是安全的?

这是更好的方法吗?

asp.net-mvc-4 asp.net-web-api

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

用于ng build --watch的VSCode task.json

我找不到针对角度cli“ ng build --watch” commapnd的有效Visual Studio Code task.json定义。有人可以提供经过良好测试的定义吗?

要重现,请尝试出现错误,然后修复它。该错误将保留在“问题”标签中

还需要“ ng lint”的任务定义。

这就是我所拥有的,并且运行不正常。

{
"version": "2.0.0",
"tasks": [
    {
        "label": "ngBuildWatch",
        "type": "shell",
        "command": "ng",
        "args": [
            "build",
            "--watch"
        ],
        "isBackground": true,
        "problemMatcher": {
            "owner": "angular",
            "severity": "error",
            "fileLocation": "relative",
            "background": {
                "activeOnStart": true,
                "beginsPattern": {
                    "regexp": "^\\s*(?:message TS6032:|\\d{1,2}:\\d{1,2}:\\d{1,2} (?:AM|PM) -) File change detected\\. Starting incremental compilation\\.\\.\\./"
                },
                "endsPattern": "/^\\s*(?:message TS6042:|\\d{1,2}:\\d{1,2}:\\d{1,2} (?:AM|PM) -) Compilation complete\\. Watching for file changes\\./ "
            },
            "pattern": [
                {
                    "regexp": "ERROR in (.*)\\(",
                    "file": 1 …
Run Code Online (Sandbox Code Playgroud)

visual-studio-code angular

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

./node_modules/pdfjs-dist/build/pdf.js 中的警告

我正在通过以下方式使用ng2-pdf-viewer

{PdfViewerModule} from 'ng2-pdf-viewer/ng2-pdf-viewer';
Run Code Online (Sandbox Code Playgroud)

从 Angular 6 开始,ng 构建显示以下错误,但应用程序仍在运行。有什么问题,我该如何解决?

未找到 ./node_modules/pdfjs-dist/build/pdf.js 模块中的警告:错误:无法解析 'C:\MyProject\node_modules\pdfjs-dist\build' 中的 'zlib'

angular

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

Angular 项目未在 docker 上使用 Visual Studio 2019 运行

我使用内置的 Angular 模板 (ASP.NET Core 3) 在 Visual Studio 2019 上创建了一个新的 Web 项目。

在此处输入图片说明

然后,我使用 Visual Studio 的向导添加了 docker 支持(右键单击项目名称 -> 添加 -> Docker 支持)。

在此处输入图片说明

当我使用 IIS Express 从 Visual Studio 启动项目时,该项目运行良好,但在使用 Docker 启动时出现以下错误:

在此处输入图片说明

在此处输入图片说明

我认为 docker 文件中缺少某些内容。这是我的内容:

在此处输入图片说明

visual-studio docker asp.net-core visual-studio-2019

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

使用主机名而不是 localhost 访问 docker 容器

我正在使用 docker-compose 和 docker。一切都很好。但是从主机访问服务的唯一方法是通过http://localhost:port。我希望能够使用容器名称进行访问,例如:http://elastic:9020

It works well inside the docker. if one container needs to access another i can use the http://elastic:9020 but not from the Host. Of Course that i am exposing the ports and using port mapping and it works using localhost as i said. Docker

UPDATE: I was looking for a native solution without the needs of installing DNS Server or updating the .host file.

docker docker-compose

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

Angular HttpClient 映射从目标对象中删除 getter

我正在使用 HttpClient 从 API 获取 Json,并使用该 HttpClient 的 autoMapping 将 json 映射到目标对象,如下所示:

this.httpClient.post<Person>(url, body, { headers: headers, params: httpParams }).retry(ConfigurationService.apiHttpRetries)
Run Code Online (Sandbox Code Playgroud)

我的问题是我的 Person 类包含如下 getter:

get FullName() { return `${this.firstName} + ' ' ${this.lastName}`; }
Run Code Online (Sandbox Code Playgroud)

在 httpClient.Post 之后,我得到一个 Person 对象,它只包含从 json 返回的字段,而不包含其他属性,并且没有我的 FullName getter。

我尝试使用 Object.Assign 但它也不起作用......

如果 httpClient.post 通用方法不做映射而只做类似 return JSON.parse(jsonResult) 的事情,它有什么大不了的?

typescript angular

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

如何使用装饰器制作对象的 JSON.stringify 输出 getter?

我需要JSON.stringify输出吸气剂的方法。我知道它没有这样做,因为吸气剂不是“可枚举的”。

我找到了一个解决方案,并且我正在使用Object.defineProperty具有可枚举属性的 getter 来增强 getter,如Playground中所示。

我想使用装饰器做同样的事情,但它不起作用,如下所示

请不要建议实现该toJSON方法,我知道它可能会有所帮助,但我想要一个仅装饰器的解决方案。

它也与 Angular 相关,因为我需要它来formGroup.patchValue为吸气剂工作。

我用 @acdcjunior 建议更新了我的示例- 希望他们能找到我在这里缺少的内容。

getter typescript typescript-decorator angular

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

TypeScript 构建属性面板已禁用

项目属性页面中的“TypeScript Build”属性面板被禁用,因此我无法更改这些值。所有字段都被禁用并变灰。我当然不是处于“运行时”模式。

在此处输入图片说明

visual-studio visual-studio-2017

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

JSON 对象的尾随逗号有什么问题

通常我会像这样创建有效的 JSON 对象:

{
  hasPermission: true,
  notificationStatusId: 1
};
Run Code Online (Sandbox Code Playgroud)

在 VSCode 上,保存文件时,有时会在最后一个属性后面自动添加尾部逗号,如下所示:

{
  hasPermission: true,
  notificationStatusId: 1,
};
Run Code Online (Sandbox Code Playgroud)

实际上我并不是问如何禁用这种行为,而且我知道如何做到这一点。我想问 VSCode 具有自动添加尾随逗号功能的原因是什么?

json visual-studio-code

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