如何在 .NET Standard 项目中使用控制台配置文件 (App.config)。
我在 App.config 中有一个控制台应用程序:
<appSettings>
<add key="Test" value="test" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
在我的 .NET Standard 项目中,我添加了 NuGet 包:
Install-Package System.Configuration.ConfigurationManager -Version 4.5.0
Run Code Online (Sandbox Code Playgroud)
并有一个返回该键值的类:
public string Test()
{
return ConfigurationManager.AppSettings["Test"];
}
Run Code Online (Sandbox Code Playgroud)
这只是为了测试我是否可以在 .NET Standard 项目中使用 App.config 设置。
但我收到此错误消息:
System.IO.FileNotFoundException: '无法加载文件或程序集 'System.Configuration.ConfigurationManager, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' 或其依赖项之一。该系统找不到指定的文件。'
当我在 Program.cs 中执行此操作时:
Class class = new Class();
string result = class.Test();
Run Code Online (Sandbox Code Playgroud) 在 MVC ASP.NET 中,您可以像这样在 web.config 文件中设置 smtp 配置:
<system.net>
<mailSettings>
<smtp from="MyEmailAddress" deliveryMethod="Network">
<network host="smtp.MyHost.com" port="25" />
</smtp>
</mailSettings>
</system.net>
Run Code Online (Sandbox Code Playgroud)
这非常有效。
但我无法让它在 .NET Core 2.2 中工作,因为你有一个 appsettings.json 文件。
我有这个 :
"Smtp": {
"Server": "smtp.MyHost.com",
"Port": 25,
"FromAddress": "MyEmailAddress"
}
Run Code Online (Sandbox Code Playgroud)
发送邮件时,它显示此错误消息:
您好,我不断收到错误消息:
<ArrayOfThemes xmlnx='http://brickset.com/api/'> was not expected.
Run Code Online (Sandbox Code Playgroud)
尝试了我在互联网上找到的一些东西,但它们都失败了。
这是我调用 SOAP Api 时的 XML 输出:
<ArrayOfThemes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="https://brickset.com/api/">
<themes>
<theme>4 Juniors</theme>
<setCount>24</setCount>
<subthemeCount>5</subthemeCount>
<yearFrom>2003</yearFrom>
<yearTo>2004</yearTo>
</themes>
</ArrayOfThemes>
Run Code Online (Sandbox Code Playgroud)
班级:
public class Themes
{
[XmlElement("theme")]
public string Theme { get; set; }
[XmlElement("setCount")]
public string SetCount { get; set; }
[XmlElement("subthemeCount")]
public string SubthemeCount { get; set; }
[XmlElement("yearFrom")]
public string YearFrom { get; set; }
[XmlElement("yearTo")]
public string YearTo { get; set; }
}
[Serializable, XmlRoot("ArrayOfThemes")]
public class ArrayOfThemes
{
[XmlElement("themes")]
public …Run Code Online (Sandbox Code Playgroud) 如何使用 Razor 在 ASP.NET Core 2.2 中根据复选框状态显示或隐藏 div 元素?
我有这个,但它不起作用:
<script>
$(function() {
$('#gridCheck1').change(function() {
$('#ShowHideMe').toggle($(this).is(':checked'));
});
});
</script>
<div class="form-group row">
<div class="col-sm-2">Checkbox</div>
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="gridCheck1">
<label class="form-check-label" for="gridCheck1">
Example checkbox
</label>
</div>
</div>
</div>
<div id="ShowHideMe">
<p>some content</p>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的项目文件夹中的库:
我尝试过这个,但这不是我想要的:
var result = myList
.GetQueryable()
.GroupBy(g => g.Name)
.Where(w => w.Name == "myName")
.AnyAsync(a => a.Count() > 1);
Run Code Online (Sandbox Code Playgroud)
true如果找到超过 1 个包含该名称的记录"myName"并且false最多"myName"找到一个名称,则应返回此结果。
我在子句中遇到编译时错误Where。但我需要检查具体值。
任何想法?
拥有这个处理程序:
public async Task<Result> Handle(MyQuery request, CancellationToken cancellationToken)
{
var cancellationTokenSource = new CancellationTokenSource();
await Parallel.ForEachAsync(myList, async (objectId, _) =>
{
var result = await _service.GetObject(objectId);
if (result.Any())
{
cancellationTokenSource.Cancel();
}
});
if (cancellationTokenSource.IsCancellationRequested) return Result.Fail("Error message.");
return Result.Ok();
}
Run Code Online (Sandbox Code Playgroud)
这可行,但想知道我CancellationTokenSource在这里使用是否正确?
.net c# async-await cancellationtokensource parallel.foreachasync
我有一个带有textarea的Razor页面,但它显示html和textarea下的按钮未显示在页面上。如果我切换到普通文本输入,则可以正常工作。
这是代码:
<div class="card-body">
<div class="form-group row">
<label class="col-sm-2 col-form-label">Text :</label>
<div class="col-sm-10">
<textarea rows="3" asp-for="MyText" class="form-control" required />
</div>
</div>
<input type="submit" value="Next" class="btn btn-primary btn-lg btn-block" />
</div>
Run Code Online (Sandbox Code Playgroud)
看到页面上的按钮未显示,并且文本区域填充了html ...
<form method="post" action="/Home/SubmitThis">
<input type="hidden" id="HiddenField1" name="HiddenField1" value="" />
<input type="hidden" id="HiddenField2" name="HiddenField2" value="" />
<div class="card">
<div class="card-body">
<div class="form-group row">
<label class="col-sm-2 col-form-label">Text :</label>
<div class="col-sm-10">
<textarea rows="3" class="form-control" required id="MyText" name="MyText" />
</div>
</div>
<input type="submit" value="Next" class="btn btn-primary btn-lg btn-block" />
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
您可以使用以下代码在 WinForm 中打开记事本:
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
public Form1()
{
InitializeComponent();
Process p = Process.Start("notepad.exe");
p.WaitForInputIdle(); // Allow the process to open it's window
SetParent(p.MainWindowHandle, this.Handle);
}
}
Run Code Online (Sandbox Code Playgroud)
在 WPF 中this.handle不被识别。this.Handle 的 WPF 版本是什么?
如何在 WPF 屏幕中没有关闭按钮的情况下全屏打开记事本?
c# ×6
razor-pages ×2
.net ×1
asp.net-mvc ×1
async-await ×1
bootstrap-4 ×1
checkbox ×1
config-files ×1
javascript ×1
linq ×1
sendmail ×1
soap ×1
wpf ×1