在我的代码我有,@Html.Partial("_StatusMessage", Model.StatusMessage)
但Visual Studio警告我:Error MVC1000: Use of IHtmlHelper.Partial may result in application deadlocks. Consider using <partial> Tag Helper or IHtmlHelper.PartialAsync.
我应该禁用此错误,还是应该@Html.Partial
改为@Html.PartialAsync
,为什么?
我第一次在ASP.NET Core中创建Authorization.我从这里使用教程TUTORIAL
问题是当我从邮递员发送请求时:
Authorization:Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6I...
Run Code Online (Sandbox Code Playgroud)
用[Authorize]属性修饰的控制器中的方法.
我401 Unauthorized
总是收到...我看到了教程的评论,似乎有些人也有类似的问题.我不知道如何解决这个问题.
是否可以在没有 *ngIf 的情况下将 (areShipsExpanded$ | async) 分配给变量?因为如果这是标志true
/false
当我有:*ngIf="(areShipsExpanded$ | async) as flag"
然后按钮不会在错误的情况下显示。
我想要这样的东西:
<button *let="(areShipsExpanded$ | async) as flag"
(click)="expandAllShips(flag)">{{(flag ? "Collapse" : "Expand"}}
</button>
Run Code Online (Sandbox Code Playgroud) 我知道如何使用Node.js在MongoDB中将对象添加到集合中,例如:
router.post('/addProduct', function (req, res) {
Partner.findByIdAndUpdate({ _id: req.body.partnerId }, { $push: { "products": { name: req.body.dataProduct.name } } }, { safe: true }, function (err, response) {
if (err) throw err;
res.json(response);
});
});
Run Code Online (Sandbox Code Playgroud)
但如果产品会是另一张桌子怎么办?我怎样才能简单地在那里添加对象?
让我们说这是我的架构:
var partnerSchema = new mongoose.Schema({
name: String,
products: [
{
name: String,
campaignList: [
{
name: String,
type: String,
startDate: Date,
endDate: Date,
paymentMethod: String,
partnerPayout: Number,
ourPayout: Number
}
]
}]
});
Run Code Online (Sandbox Code Playgroud)
在每个ID partner
和product
是默认._id
例如.partner._id
和product._id …
在 Angular Material 的文档中有一个很酷的功能。带有可以展开/折叠的子类别的菜单。
是否可以使用某些组件创建它?还是我必须自己从头开始?或者,也许您可以向我推荐一些可以节省我时间的软件包。
在我的 .net core 3.1 应用程序中,我想将属性封装在某个实体中:
public class Sample : AuditableEntity
{
public Sample(string name)
{
Name = name;
}
public int Id { get; }
public string Name { get; }
}
Run Code Online (Sandbox Code Playgroud)
因此,我删除了所有公共设置器,因此当我想检查此类 Sample 是否已存在时,我的代码中的某个位置
_context.Samples.Any(r => r.Name == name)
Run Code Online (Sandbox Code Playgroud)
该行导致错误:System.InvalidOperationException: 'No suitable constructor found for entity type 'Sample'. The following constructors had parameters that could not be bound to properties of the entity type: cannot bind 'name' in 'Sample(string name)'.'
。
所以我添加了代码空构造函数
public class Sample : AuditableEntity
{ …
Run Code Online (Sandbox Code Playgroud) .net c# entity-framework-core .net-core entity-framework-core-3.1
我正在制作CRUD,如果我想将一些数据发送到我的后端(node.js),那么我收到一个错误:
angular.js:10765 POST http://localhost:1234/shop/removeProduct/574bf938b16158b40f9c87bc 400 (Bad Request)
脚本:
$scope.removeProduct = function (partnerId, productId) {
$http.post("/campaign/removeProduct/" + partnerId, productId);
}
Run Code Online (Sandbox Code Playgroud)
解决方案就是将这个参数(productId
)简单地打包在这样的对象中:
$scope.removeProduct = function (partnerId, productId) {
$scope.productData = {productId: productId};
$http.post("/campaign/removeProduct/" + partnerId, $scope.productData);
}
Run Code Online (Sandbox Code Playgroud)
但为什么我必须这样做呢?顺便说一下,这是正确的还是应该以不同的方式进行?
@EDIT还有一件事,我添加/删除任何对象后应该如何刷新数据?它是否正确?
$scope.addPartner = function(data) {
$http({method: 'POST', url: addPartner, data})
.then(function(response) {
console.log(response);
});
$scope.loadPartnersData();
window.alert("Partner added!");
};
$scope.loadPartnersData = function () {
$http.get("/campaign/partner-list").then(function(result) {
$scope.partnerList = result.data.partnerList;
});
};
Run Code Online (Sandbox Code Playgroud)
后端:
router.get('/partner-list', function (req, res) {
Partner.find({}, function (err, partnerList) {
if …
Run Code Online (Sandbox Code Playgroud) 根据这里的信息.
我找到了如何使用Entity Framework删除孤儿.
public void SaveChanges()
{
context.ReportCards
.Local
.Where(r => r.Student == null)
.ToList()
.ForEach(r => context.ReportCards.Remove(r));
context.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
我想知道如何为这部分制作通用函数,因为它可能经常被使用:
context.ReportCards
.Local
.Where(r => r.Student == null)
.ToList()
.ForEach(r => context.ReportCards.Remove(r));
Run Code Online (Sandbox Code Playgroud)
我想过这样的事情:
public void SaveChanges()
{
RemoveOrphans(Student, ReportCards)
context.SaveChanges();
}
private void RemoveOrphans<T>(T sourceContext, T orphan)
{
context.orphan
.Local
.Where(r => r.sourceContext == null)
.ToList()
.ForEach(r => context.orphan
.Remove(r));
}
Run Code Online (Sandbox Code Playgroud)
但当然它不起作用.有什么建议?
我有带有 Angular 的 IdentityServer4。令牌每 5 分钟静默刷新一次。但是 30 分钟后,用户将自动注销。我试图以某种方式设置终身 cookie,但没有成功。
这是我目前的配置:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<AppIdentityDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("Identity")));
services.AddIdentity<AppUser, IdentityRole>(options =>
{
options.Password.RequiredLength = 6;
options.Password.RequireLowercase = false;
options.Password.RequireUppercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireDigit = false;
options.SignIn.RequireConfirmedEmail = true;
options.User.RequireUniqueEmail = true;
options.User.AllowedUserNameCharacters = null;
})
.AddEntityFrameworkStores<AppIdentityDbContext>()
.AddDefaultTokenProviders();
services.AddIdentityServer(options => options.Authentication.CookieLifetime = TimeSpan.FromHours(10))
.AddDeveloperSigningCredential()
.AddInMemoryPersistedGrants()
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients(Configuration["AppUrls:ClientUrl"]))
.AddAspNetIdentity<AppUser>();
services.AddTransient<IProfileService, IdentityClaimsProfileService>();
services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()));
services.AddRazorPages().AddRazorRuntimeCompilation();
}
Run Code Online (Sandbox Code Playgroud)
@编辑
如果我会添加
services.Configure<SecurityStampValidatorOptions>(options =>
{
options.ValidationInterval = TimeSpan.FromHours(24); …
Run Code Online (Sandbox Code Playgroud)