我有一些想做经常性工作的方法。
我知道我可以在我的Startup.cs中使用hangfire,例如:
RecurringJob.AddOrUpdate(() => Console.WriteLine("I'm a recurring job"), Cron.Minutely);
Run Code Online (Sandbox Code Playgroud)
但是问题是我如何在这里使用我的服务?我应该在这里(依赖注入吗?)还是在其他地方使用?
也许我应该在appsettings.json中添加一些cron值?
我正在尝试创建运行 ASP.NET Core 应用程序和 mssql 的 docker compose,但在构建过程中遇到错误。
这是我的 docker 撰写文件:
# Build Stage
FROM microsoft/aspnetcore-build:latest as build-env
WORKDIR /source
COPY . .
RUN dotnet restore ./Travelingowe.sln
RUN dotnet publish --output ${source:-obj/Docker/publish} --configuration Release
# Publish Stage
FROM microsoft/aspnetcore:latest
COPY --from=build-env ./obj/Docker/publish /app
WORKDIR /app
ENTRYPOINT ["dotnet", "Api.dll"]
Run Code Online (Sandbox Code Playgroud)
当我在 CMD -> docker-compose up中运行时,我得到:
Building api
Step 1/9 : FROM microsoft/aspnetcore-build:latest as build-env
---> d6273f7c44d4
Step 2/9 : WORKDIR /source
---> Using cache
---> 978f1c31e14a
Step 3/9 : COPY . …Run Code Online (Sandbox Code Playgroud) 我点击按钮后,我想让我的表单可编辑.
我为单击按钮编写代码,但我不知道如何更改表单中输入的状态.
viewModel.test= function () {
//code here
}
<input type="text"/> // Enable/Disable this
Run Code Online (Sandbox Code Playgroud)
我可以禁用/启用表单中的所有输入,或者我只需要逐个执行此操作吗?
我正在尝试将图像添加到 pdf 单元格,但出现错误:
参数 1:无法从“System.Drawing.Image”转换为“iTextSharp.text.pdf.PdfPCell”
排队:
content.AddCell(myImage);
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
PdfPTable content = new PdfPTable(new float[] { 500f });
content.AddCell(myImage);
document.Add(content);
Run Code Online (Sandbox Code Playgroud)
myImage变量是图像类型。我究竟做错了什么?
我想在我的ASP.NET核心应用程序中使用Hangfire,我有错误消息:
没有注册类型服务
这是我的代码:服务:
public class MyService: IMyService
{
private readonly MyContext _context;
public MyService(MyContext context)
{
_context = context;
}
// some code
}
public interface IMyService
{
//some code
}
Run Code Online (Sandbox Code Playgroud)
在Startup.cs中:
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IMyService, MyService>();
// another services
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider serviceProvider)
{
app.UseHangfireDashboard();
app.UseHangfireServer();
RecurringJob.AddOrUpdate(() => serviceProvider.GetService<IMyService>().MyMethod(), Cron.Minutely);
}
Run Code Online (Sandbox Code Playgroud)
你知道服务没有注册的原因吗?
我在asp.net核心中遇到SyndicationFeed的问题。我知道还没有移植到asp.net核心,但是我也使用完整的.net框架,因此我认为它应该可以工作。
这是我的错误代码:
SyndicationFeed feed = SyndicationFeed.Load(reader);
Run Code Online (Sandbox Code Playgroud)
这是我的project.json
{
"dependencies": {
"Microsoft.AspNetCore.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.Mvc": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.AspNetCore.StaticFiles": "1.1.0",
"Microsoft.Extensions.Configuration.CommandLine": "1.1.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.1.0",
"Microsoft.Extensions.Logging.Debug": "1.1.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.AspNetCore.AngularServices": "1.1.0-beta-000002",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.1.0-preview4-final",
"type": "build"
},
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"System.Xml.ReaderWriter": "4.3.0"
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.DotNet.Watcher.Tools": "1.1.0-preview4-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
},
"imports": [
"dotnet5.6", …Run Code Online (Sandbox Code Playgroud) 如何将例如2个字符串传递给Func并返回一个字符串?假设我要传递FirstName和LastName,结果应类似于FirstName + LastName;
此外,我想将Func声明为属性。
请看一下我的代码:
public class FuncClass
{
private string FirstName = "John";
private string LastName = "Smith";
//TODO: declare FuncModel and pass FirstName and LastName.
}
public class FuncModel
{
public Func<string, string> FunctTest { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
您能帮我解决这个问题吗?
我想在 ASP.NET 中使用 ZXing.NET 生成 EAN 13 条码并将其转换为 base64 字符串。
我在如何转换 BarcodeWriterPixelData 时遇到问题:
BarcodeWriterPixelData writer = new BarcodeWriterPixelData()
{
Format = BarcodeFormat.EAN_13
};
var pixelData = writer.Write(barcodeModel.BarcodeNumber);
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 ImageSharp
var base64String = string.Empty;
using (Image<Rgba32> image = Image.Load<Rgba32>(pixelData.Pixels))
{
base64String = image.ToBase64String();
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用。
我想知道是否可以通过前缀获取所有 Azure Key Vault Secret。
假设我有 3 个秘密。
key: pre-secret1
value: value1
key: secret2
value: value2
key: pre-secret3
value: value3
Run Code Online (Sandbox Code Playgroud)
我想获取所有带有前缀 pre 的秘密并将它们序列化为 JSON。将来,我将有更多带有前缀的秘密,所以我不想手动读取秘密。因此,当我添加带有前缀的新密钥时,我的函数也会返回带有新值的 JSON。
问题是:是否可以通过前缀从 Azure Key Vault 获取机密并动态序列化为 JSON?
更新:我想在 ASP.NET Core 3.1 和 C# 中使用它。更新2:我添加了如何获得一个秘密。
var client = new SecretClient(vaultUri: new Uri(kvUri), credential: new DefaultAzureCredential(true));
var secret = client.GetSecret("secret-name");
Run Code Online (Sandbox Code Playgroud) 我想合并两个不重复的列表。它应该仅由一个属性来区分。
我有一堂课:
public class Test
{
public int Id { get; set; }
public string Prop { get; set; }
public string Type { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有两个列表,我想按类型合并它们而不重复。因此,首先我想从列表 1 中获取所有内容,然后当列表 1 中不存在 Type 时从列表 2 中获取所有内容。
我试过联合。
c# ×8
.net ×6
asp.net-core ×5
asp.net-mvc ×3
asp.net ×2
hangfire ×2
.net-4.0 ×1
.net-core ×1
azure ×1
barcode ×1
delegates ×1
docker ×1
dockerfile ×1
func ×1
html ×1
ienumerable ×1
input ×1
itext ×1
javascript ×1
knockout.js ×1
linq ×1
list ×1
pdf ×1
zxing ×1