我正在开发一个 Web 应用程序,使用Angular 6 和 PrimeNG控件进行前端开发,使用ASP.Net Web API 和 SQL Server进行后端开发。
在我的一个表单中,有两个 PrimeNG Calender 控件用于将起始日期和结束日期保存到数据库中。提交表单后,所有表单字段都会被收集以填充对象/模型,并将该模型传递给 Web API。对象/模型是使用 Typescript 代码在 Angular 6 中填充的。下面是我的 Typescript 代码中的前端模型:
export class MyPackage {
public PackageId: number;
public PackageUid: number;
public PackageName: string;
public PackageDesc: string;
public ValidFrom: Date;
public ValidTill: Date;
public CreatedOn: Date;
}
Run Code Online (Sandbox Code Playgroud)
这是我使用 Angular 6 和 typescript 的对象初始化过程:
let pakg = new MyPackage();
pakg.PackageName = this.packageAddForm.controls["packageName"].value;
pakg.PackageDesc = this.packageAddForm.controls["packageDesc"].value;
pakg.ValidFrom = this.packageAddForm.controls["dateFrom"].value;
pakg.ValidTill = this.packageAddForm.controls["dateEnd"].value;
Run Code Online (Sandbox Code Playgroud)
现在的问题是,当模型传递到 Web API …
我正在尝试在 .NET Core 3.1 中开发一个项目。我正在尝试在我的项目中实现基于 cookie 的身份验证。我的登录功能是:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(UserLoginModel userModel)
{
if (!ModelState.IsValid)
{
return View(userModel);
}
if (userModel.Email == "admin@test.com" && userModel.Password == "123")
{
var identity = new ClaimsIdentity(IdentityConstants.ApplicationScheme);
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "User Id"));
identity.AddClaim(new Claim(ClaimTypes.Name, "User Name"));
var principal = new ClaimsPrincipal(identity);
await HttpContext.SignInAsync(IdentityConstants.ApplicationScheme, principal);
return RedirectToAction(nameof(HomeController.Index), "Home");
}
else
{
ModelState.AddModelError("", "Invalid UserName or Password");
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
为了实现基于 cookie 的身份验证,我将以下代码放入 Startup 类的 ConfigureService 方法中:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.Configure<CookiePolicyOptions>(options …Run Code Online (Sandbox Code Playgroud) 我有父组件,有一个ng-template部分。在这个 ng-template 部分下有一个Child Component。现在我想使用 ViewChild 装饰器访问这个子组件。使用 ViewChild 后,我想执行该子组件的功能。但它不起作用。代码如下:
<ng-template #mymodal let-modal>
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">Bootstrap Modal</h4>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<app-expense-head #child></app-expense-head>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" (click)="modal.close('Save click')">Ok</button>
<button type="button" class="btn btn-outline-dark" (click)="onClickCancel()">Cancel</button>
</div>
</ng-template>
Run Code Online (Sandbox Code Playgroud)
TS文件代码
@ViewChild(ExpenseHeadComponent, { static: false }) childExpenseHead: ExpenseHeadComponent;
onClickCancel() {
this.childExpenseHead.myAlert();
}
Run Code Online (Sandbox Code Playgroud) 我已经开发了一个自定义验证器Attribute类,用于检查模型类中的Integer值。但问题是此类无法正常工作。我已经调试了我的代码,但是在调试代码期间没有遇到断点。这是我的代码:
public class ValidateIntegerValueAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value != null)
{
int output;
var isInteger = int.TryParse(value.ToString(), out output);
if (!isInteger)
{
return new ValidationResult("Must be a Integer number");
}
}
return ValidationResult.Success;
}
}
Run Code Online (Sandbox Code Playgroud)
我还有一个Filter类,用于在应用程序请求管道中全局进行模型验证。这是我的代码:
public class MyModelValidatorFilter: IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
if (context.ModelState.IsValid)
return;
var errors = new Dictionary<string, string[]>();
foreach (var err in actionContext.ModelState)
{
var itemErrors = new List<string>();
foreach (var error in err.Value.Errors){ …Run Code Online (Sandbox Code Playgroud) 我们将在下一个项目中实施TDD方法.所以我一直在使用ASP.NET Core中的NUnit进行单元测试.因为我是新手,所以我对一些事感到困惑.因此,我想与您分享这些问题,以便根据专家意见做出决定.
请帮我找到这些问题的答案.可能是这样,有些问题是相似的,但是,我不想删除它们以便更好地理解你们.谢谢.
我正在准备使用Groovy语言的Jenkins管道脚本。我想将所有文件和文件夹移动到另一个位置。由于Groovy支持Java,因此我在下面的Java代码中执行了该操作。
管道{代理任何
stages{
stage('Organise Files'){
steps{
script{
File sourceFolder = new File("C:\\My-Source");
File destinationFolder = new File("C:\\My-Destination");
File[] listOfFiles = sourceFolder.listFiles();
echo "Files Total: " + listOfFiles.length;
for (File file : listOfFiles) {
if (file.isFile()) {
echo file.getName()
Files.copy(Paths.get(file.path), Paths.get("C:\\My-Destination"));
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
此代码引发以下异常:
groovy.lang.MissingPropertyException:无此类属性:类文件:WorkflowScript
我也尝试了下面的代码,但也不起作用。
FileUtils.copyFile(file.path, "C:\\My-Destination");
Run Code Online (Sandbox Code Playgroud)
最后,我确实尝试使用java I / O Stream执行操作,并且代码如下:
def srcStream = new File("C:\\My-Source\\**\\*").newDataInputStream()
def dstStream = new File("C:\\My-Destination").newDataOutputStream()
dstStream << srcStream
srcStream.close()
dstStream.close()
Run Code Online (Sandbox Code Playgroud)
但它也不起作用,并引发以下异常:
java.io.FileNotFoundException:C:\ My-Source(访问被拒绝)
谁能建议我解决问题的方法,也请让我知道复制或移动文件后如何从源位置删除文件?还有一件事,在复制期间我可以使用通配符过滤一些文件夹和文件吗?也请让我知道。
我正在 Angular 12 和最新的 NgRx 库中创建一个应用程序以供参考。我有以下模型、操作、减速器和应用程序状态类。
模型
export interface Tutorial {
name: string;
url: string;
}
Run Code Online (Sandbox Code Playgroud)
行动
import { Injectable } from '@angular/core'
import { Action } from '@ngrx/store'
import { Tutorial } from '../_models/tutorial.model'
export const ADD_TUTORIAL = '[TUTORIAL] Add'
export const REMOVE_TUTORIAL = '[TUTORIAL] Remove'
export class AddTutorial implements Action {
readonly type = ADD_TUTORIAL
constructor(public payload: Tutorial) {}
}
export class RemoveTutorial implements Action {
readonly type = REMOVE_TUTORIAL
constructor(public payload: number) {}
}
export type Actions …Run Code Online (Sandbox Code Playgroud) 我正在 .NET 6 中的Blazor Server 版本中创建一个 Web 应用程序。为了进行身份验证,我使用ASP.NET Core Identity。现在我的应用程序中需要一个功能。如果应用程序空闲一段特定时间(例如 10 分钟),它将注销。我已在我的文件中添加了以下代码Program.cs。但问题是在特定时间跨度之后,如果我刷新应用程序,它就会注销。但如果我点击应用程序的任何链接,什么也不会发生。
builder.Services.ConfigureApplicationCookie(options =>
{
// Cookie settings
options.Cookie.HttpOnly = true;
options.Cookie.Name = "Horus";
options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
options.LoginPath = "/Identity/Account/Login";
options.LogoutPath = "/Identity/account/logout";
options.AccessDeniedPath = "/Identity/Account/Login";
options.SlidingExpiration = true;
});
Run Code Online (Sandbox Code Playgroud)
如果我点击任何链接,我还应该做什么才能注销?另一件事是这条线
options.ExpireTimeSpan = TimeSpan.FromMinutes(5)
Run Code Online (Sandbox Code Playgroud)
真的会计算空闲时间吗?请告诉我。
angular ×2
asp.net-core ×2
angular6 ×1
blazor ×1
c# ×1
datetime ×1
java-stream ×1
moq ×1
ng-template ×1
ngrx ×1
tdd ×1
unit-testing ×1
viewchild ×1