对于一对多关系,HasMany和OwnsMany 有什么区别?我什么时候应该使用一个?
例如:
public class xxx
{
public virtual IReadOnlyCollection<xxxHistoryEntity> Histories => _histories;
private readonly List<xxxHistoryEntity> _histories = new List<xxxHistoryEntity>();
}
public class xxxHistoryEntity : Entity<string>
{
public string State { get; set; }
public string NodeId { get; set; }
public string Message { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
实体配置:
class xxxConfiguration
: IEntityTypeConfiguration<xxx>
{
public void Configure(EntityTypeBuilder<xxx> builder)
{
builder.OwnsMany(itm => itm.Histories, collbuilder =>
{
collbuilder.HasForeignKey("xxxid");
});
}
}
class xxxHistoryConfiguration …
Run Code Online (Sandbox Code Playgroud) 我试图使用TypeScript <PrivateRoute>
在react-router 文档中创建一个as describe .谁能帮我吗?
react-router文件中的privateRoute:
const PrivateRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={props => (
fakeAuth.isAuthenticated ? (
<Component {...props}/>
) : (
<Redirect to={{pathname: '/login', state: { from: props.location }
}}/>
)
)}/>
)
Run Code Online (Sandbox Code Playgroud)
下面是我的TypeScript版本(它不起作用):
const PrivateRoute = (theProps: { path: string, component: React.SFC<RouteComponentProps<any> | undefined> | React.ComponentClass<RouteComponentProps<any> | undefined> }) => {
return <Route path={theProps.path} render={props => (
fakeAuth.isAuthenticated ? (
<React.Component {...theProps} /> <!-- **** It will raise error …
Run Code Online (Sandbox Code Playgroud) typescript reactjs react-router typescript2.0 react-router-v4
对不起,如果它是重复的,我已经搜索了很多,但我找不到匹配的问题.
我知道我们不应该在一个事务中更新多个聚合实例.但是,我认为"多个聚合实例"在这里意味着不同聚合类型的多个实例.我对吗?
比如,Product和BacklogItem是两个不同的聚合,因此我们应该避免在一个事务中更新Product和BacklogItem.
但是,如果我需要更新相同聚合类型的多个实例呢?说,我需要更新所有产品的名称.处理它的最佳方法是什么?
伪代码
//Application Service
public void ChangeTitle(string newName)
{
using(uow.BeginTransaction())
{
IEnumerable<Product> products = repo.GetAll();
foreach(var product in products)
{
product.ChangeName(newName);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我将asp.net core 2.1 WebApi部署到IIS10。(IIS充当代理)
我在IIS中添加了SSL证书,并为不安全端口(8081)和安全端口(8082)进行了绑定。
但是,当我访问http:// localhost:8081 / api / values时,浏览器只会返回403 Forbidden,而不会将我重定向到https:// localhost:8082 / api / values。
我的启动代码如下:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddHttpsRedirection(options=>
{
options.HttpsPort = 8082;
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
//app.UseForwardedHeaders();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud) 我正在评估有关分布式日志服务器的不同选项。
在Java世界,我看到的最流行的方案是filebeat + kafka + logstash + elasticsearch + kibana。
但是,在 .NET 世界中,有一个 serilog 可以将结构日志直接发送到 elasticsearch。所以唯一需要的组件是elasticsearch + kibana。
我搜索了很多,但是关于这个解决方案在生产中的信息并不多。我不知道它是否足以处理大量日志。
谁能给我一些建议?谢谢。
我知道openId connect可以发出一个Id令牌,客户端(依赖方)可以使用它来验证最终用户.但它如何用于保护资源服务器免受客户端模拟?(我认为这个问题与使用隐式授权的OAuth应用程序中的客户端模拟非常相似)
比如,有一个SPA(android + webAPI),客户端(android app)实现了openid connect隐式流,并将直接使用访问令牌与资源服务器(web api)进行通信.该应用程序首先将最终用户重定向到openid提供程序,并获得id令牌和访问令牌.但是,有一个恶意应用程序窃取访问令牌并模拟客户端与资源服务器通信.
如果没有id令牌,资源服务器如何知道访问令牌是否被盗?
问题与此非常相似,但我的重点是默认功能。(我是前端新手,如果有更正式的名称,请告诉我)
这是代码(我使用的是 TypeScript 2.5):
export const TestProps = {
Hello: (name: string) => {
console.log(name);
}
}
type TestPropsType = typeof TestProps;
export class TestComp extends React.Component<TestPropsType, {}>{
public render() {
this.props.Hello("world");
return <div>test</div>;
}
}
Run Code Online (Sandbox Code Playgroud)
然后,当我尝试渲染此组件时:
ReactDOM.render(<TestComp />, document.getElementById("page"));
Run Code Online (Sandbox Code Playgroud)
我有这个错误?
TS2322:类型“{}”不可分配给类型“IntrinsicAttributes & IntrinsicClassAttributes & Readonly<{ children?: ReactNode; }> & ...'。类型 '{}' 不能分配给类型 'Readonly<{ Hello: (name: string) => void; }>'。
类型“{}”中缺少属性“Hello”。
我该如何解决这个问题?
它是一个asp.net核心webapi项目,我只是把[Authorize]属性放在了保护那些apis上。如果用户未授权,api 将返回“401 未授权”。
我的问题是如果未经授权,我如何本地化“401 未授权”消息。
对于其他数据注释,我可以设置DataAnnotation 属性的ErrorMessage属性,例如 [Required(ErrorMessage = "xxx")]。但是,AuthorizeAttribute 没有这样的属性。
感谢@Athanasios,我想出了我的解决方案,希望它可以帮助某人。(ErrorMessages 只是一个共享类)。
using System;
using System.Threading.Tasks;
using YourNamespace.Messages;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
namespace YourNamespace.Attributes
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class LocalizedAuthorizeAttribute : AuthorizeAttribute, IAsyncAuthorizationFilter
{
public string UnauthorizedErrorMessage { get; set; }
public string ForbiddenErrorMessage { get; set; }
public LocalizedAuthorizeAttribute()
{
}
public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{ …
Run Code Online (Sandbox Code Playgroud) 我们的项目使用 Gitlab,并且有两个长期存在的分支:dev 和 master,类似于 Git Flow。我们使用“合并提交”方法,它将在主分支中创建合并提交。
然而,由于这些“合并提交”,主分支将始终领先于开发分支。
所以,我的问题是,我应该将这些“合并提交”合并回开发分支吗?为什么?
我读了很多关于 OIDC 和 OAuth2 的内容,我知道 id token 主要用于客户端了解用户是谁以及用户当前是否仍然在线。
此外,Id令牌可以防止一类冒充攻击[您可以在本文中找到更多详细信息]。
但如果 id 令牌被盗怎么办?攻击者可以使用 id 令牌来冒充用户吗?
在我们的项目中,除了OIDC之外,我们只确保https。我还应该采取哪些安全考虑来减轻假冒攻击?
asp.net-core ×2
c# ×2
oauth-2.0 ×2
reactjs ×2
security ×2
typescript ×2
ef-core-2.2 ×1
git ×1
gitlab ×1
iis ×1
react-router ×1
serilog ×1