RE:Angular2 2.0.0,angular-cli v1.0.0-beta.11-webpack.8
如何在构建时告诉angular-cli在"dist"的根目录中包含"src/assets"中的文件?
我们部署到Windows主机,需要包含一个"web.config"文件,告诉IIS将所有内容路由到索引.我们正在做这个预备RC4,但随着所有的更新它落在了裂缝(我不记得我们是如何做到的).
我一直在搜索GitHub repo文档,但没有找到任何关于这个主题的用法.也许我在错误的地方?
在ToC中,有一个项目符号"向构建中添加额外的文件",但似乎该部分不存在.
给定以下自动生成的 Visual Studio Code launch.json 配置:
我希望localhost:5000/swagger
在调试时启动浏览器,但我已经尝试了六种不同的东西,但没有任何效果。它只是打开到localhost:5000
. 我在这里缺少什么?除了按 Ctrl+空格键查看列表之外,没有关于所有可用属性的通用文档(我可以找到),这没有多大帮助。
我遗漏了我试图让它按照我想要的方式工作的失败尝试......
{
"name": "Launch Demo.Api",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/Demo.Api/bin/Debug/netcoreapp2.1/Demo.Api.dll",
"args": [],
"cwd": "${workspaceRoot}/Demo.Api",
"stopAtEntry": false,
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
Run Code Online (Sandbox Code Playgroud) 环境:.Net Core 1,EF,使用Identity进行身份验证,使用JWT令牌进行授权.
遇到问题,使用UserManager.ChangePasswordAsync()
方法IS正确更新数据库,但不更新UserManager.Users
列表(假设).
在Startup.cs中,我们只是使用app.UseIdentity()
,在ApplicationUserService
构造函数中,我们正在注入UserManager<ApplicationUser>
.除此之外,我们没有做任何习惯.
例如:假设用户将其密码从"password1"更改为"password2".如果该用户注销并重新登录,则UserManager仍认为密码为"password1".如果我重新启动WebAPI服务器,则尝试登录; 它可以像你期望的那样使用"password2".所以它肯定会更新数据库,但UserManager的范围/缓存没有更新.
我想知道UserManager的默认DI范围是否是单例(而不是每个请求)?如果它没有更新UserStore的缓存用户列表,我可以看到导致此问题.
有什么建议?需要更多代码?
ApplicationUserService(简化):
private readonly UserManager<ApplicationUser> _userManager;
public ApplicationUserService(UserManager<ApplicationUser> userManager)
{
_userManager = userManager;
}
public Task<IdentityResult> ChangePasswordAsync(ApplicationUser user, string currentPassword, string newPassword)
{
return _userManager.ChangePasswordAsync(user, currentPassword, newPassword);
}
Run Code Online (Sandbox Code Playgroud)
[编辑]
我不确定为什么会出现这种情况,但我刚才意识到,如果我将UserManager和SignInManager直接注入到Controller的构造函数中(而不是注入Service层),它似乎工作得很好.
[编辑2]
调查结果摘要:
1)将UserManager和SignInManager注入到Service构造函数中,然后将该Service注入Controller构造函数不起作用.
2)将UserManager和SignInManager注入Controller构造函数.
3)我还在Controller构造函数中测试了IServiceProvider的使用.我注入了IServiceProvider,然后使用GetService方法设置管理器:_userManager = serviceProvider.GetService<UserManager<ApplicationUser>>();
.这与#1的结果相同.
在#1和#3中:它将保存到数据库,但管理员似乎在以后使用时不知道数据更改.在这两种情况下,我都必须重新初始化应用程序(停止并启动服务器),以便更新缓存的数据.
不应该#3和#2一样工作吗?
使用一个WebApi
项目和一个Data
包含实体框架实现的单独项目来处理DotNetCore 解决方案。我们一直在升级库,所以我们使用了所有最新的 Core 东西。
在Data
项目中,我们创建了一个ApplicationDbContextFactory
以创建迁移(需要一个无参数的构造函数)。由于添加迁移时的无参数构造函数约束,您无法通过注入IOptions<>
轻松访问appsettings.json
值。我们最终使用 aConfigurationBuilder
来拉入WebApi
'sappsettings.json
文件。
我们最近更改了ApplicationDbContextFactory
也拉入user-secrets
。这允许每个开发人员使用自定义连接字符串,而不必忽略文件或记住不要提交某些内容。
由于进行了此更改,因此dotnet ef migrations add MIGRATION_NAME
在命令行中使用效果很好。但是,add-migration MIGRATION_NAME
在 Visual Studio 的包管理器控制台中使用现在似乎被破坏并出现以下错误:
add-migration : 使用“1”参数调用“Substring”的异常:“StartIndex 不能小于零。参数名称:startIndex” At line:1 char:1 + add-migration TESTING + ~~~~~~ ~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Add-Migration], MethodInvocationException +fullyQualifiedErrorId : ArgumentOutOfRangeException,Add-Migration
我尝试了该命令的一些变体,以查看它是否需要指定上下文(除其他外),但似乎没有任何方法可以解决此错误。它似乎永远不会超过ApplicationDbContextFactory
.
这是我所指的代码:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Models.Domain.Settings;
using …
Run Code Online (Sandbox Code Playgroud) 我们有一个相当简单netstandard2.0
的自定义中间件项目,它使用 Serilog 的静态 LogContext 将指定的 HttpContext 标头复制到日志上下文。
我正在尝试编写一个单元测试,在其中设置一个使用 aDelegatingSink
写入变量的记录器。然后它执行Invoke()
中间件方法。然后我尝试使用该事件来断言已添加的属性。到目前为止,中间件添加的属性没有显示,但我在测试中添加的属性显示了。我假设它正在处理不同的上下文,但我不确定如何解决这个问题。我尝试了几种不同的方法,但都没有奏效。
由于LogContext
是静态的,我认为这会很简单,但我低估了一些东西。这就是我现在所处的位置(为简洁起见省略了一些代码)。我做了确认LogContext.PushProperty
中间件的线是被击中在运行时休息。
考试:
...
[Fact]
public async Task Adds_WidgetId_To_LogContext()
{
LogEvent lastEvent = null;
var log = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Sink(new DelegatingSink(e => lastEvent = e))
.CreateLogger();
// tried with and without this, also tried the middleware class name
//.ForContext<HttpContextCorrelationHeadersLoggingMiddlewareTests>();
var context = await GetInvokedContext().ConfigureAwait(false);
LogContext.PushProperty("MyTestProperty", "my-value");
log.Information("test");
// At this point, 'lastEvent' only has the property "MyTestProperty" :(
} …
Run Code Online (Sandbox Code Playgroud) create-react-app
在过去的几个月里,我一直在开发几个+ TypeScript 应用程序。在某些时候(我可能升级了 lib) tslint 开始this.setState({ [name]: value })
在状态被赋予类型时抛出错误。它曾经让它滑动(除非我快疯了......不是不可能的)。
让 tslint 闭嘴的唯一方法是将状态类型更改为any
,我不想这样做。如果我保存文件并yarn start
获取更改,它运行良好......所以我可以忽略 tslint 在 vscode 中抛出的错误。
我明白为什么 tslint 会抛出错误。我想知道是否有规则可以设置为忽略此特定错误?
我看到这个的例子(第5行):
class MyComponent extends React.Component<IMyComponentProps, IMyComponentState> {
...
private handleOnChange = (event: any) => {
const { name, value } = event.target;
this.setState({ [name]: value }); <-- tslint no likey
}
Run Code Online (Sandbox Code Playgroud)
错误:
[ts] '{ [x: number]: any; 类型的参数 }' 不可分配给类型为 'IMyComponentState| 的参数 ((prevState: Readonly, pro...'. Type '{ [x: number]: any; }' 不可分配给 type …
有人可以向我解释为什么try/catch不能处理"Uncaught SyntaxError"吗?是否可以优雅地处理这种类型的错误,以便JS的其余部分运行?
例如:
try { response.write(;); }
catch(e) { console.log(e); }
Run Code Online (Sandbox Code Playgroud)
此代码抛出"Uncaught SyntaxError:Unexpected token;" [Chrome]浏览器错误,而不是跳转到catch并记录错误对象.你在Firefox中也得到了类似的结果; 抛出错误而不是使用catch处理它.
c# ×3
asp.net-core ×2
angular ×1
angular-cli ×1
console ×1
debugging ×1
identity ×1
javascript ×1
reactjs ×1
serilog ×1
syntax-error ×1
try-catch ×1
tslint ×1
typescript ×1
unit-testing ×1
usermanager ×1