如何使用LINQ将嵌套的分层对象转换为展平对象?我知道我们可以轻松使用foreach循环来实现这一点.但我想知道是否有办法在LINQ中编写它.
class Person{
public int ID {get;set}
public string Name {get;set}
public List<Person> Children {get;}
}
Run Code Online (Sandbox Code Playgroud)
数据:
ID : 1
Name : Jack
Children
2 | Rose
3 | Paul
Run Code Online (Sandbox Code Playgroud)
我喜欢将此数据转换为扁平格式,如下所示.
1 | Jack
2 | Rose
3 | Paul
Run Code Online (Sandbox Code Playgroud)
我们怎么能用Linq做到这一点?
Sitecore包向导可用于构建包含本地Sitecore实例的数据和文件的包.
是否可以从命令行构建Sitecore包(仅限项目,不需要文件),或者在网站的上下文之外?我们的想法是使用Nant创建Sitecore数据包.我知道Hedgehog TDS,但这个问题针对的是现有的Sitecore api可以做些什么.
msbuild nant build-automation continuous-integration sitecore
在MVC 5.2.2中,我可以设置Routes.AppendTrailingSlash为true,以便将尾部斜杠附加到URL.
但是我还有一个机器人控制器,它返回robots.txt的内容.
如何防止将Slash附加到robots.txt路由并使其在尾部斜杠中调用?
我的控制器代码:
[Route("robots.txt")]
public async Task<ActionResult> Robots()
{
string robots = getRobotsContent();
return Content(robots, "text/plain");
}
Run Code Online (Sandbox Code Playgroud)
我的路线配置看起来像这样:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home",
action = "Index",
id = UrlParameter.Optional }
);
RouteTable.Routes.AppendTrailingSlash = true;
Run Code Online (Sandbox Code Playgroud) 我似乎总是遇到这个错误:
路由表中的路由与提供的值不匹配.
在执行当前Web请求期间发生了未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
堆栈跟踪只是一堆MVC垃圾.
显然我正在查询不存在的路由,但是如何找到它实际尝试查询的路由?我很想知道实际的URL和HTTP方法.我该怎么发现这个?
(我已经习惯了Django,其中尝试过的URL是异常的一部分,并且更喜欢比查看我的页面源并找出它更有效的方法.)
即时通讯使用jquery与asp.net mvc.我正在做这样的事情,以便在单击时禁用提交按钮.
但如果有验证错误,我不希望它被禁用.
$('form').submit(function () {
if ($('form').valid()) {
$('input[type=submit]', this).attr('disabled', 'disabled');
}
});
Run Code Online (Sandbox Code Playgroud)
这使它被禁用,但即使存在验证错误.怎么了?
根web.config文件中的此规范是否正确?我没有在受保护的文件夹中使用子web.config.
<system.web>
<authentication mode="Forms">
<forms name=".ASPXAUTH" loginUrl="">
</forms>
</authentication>
</system.web>
Run Code Online (Sandbox Code Playgroud)
然后另一个system.web规范也在root web.config中:
<location path="to protected folder">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
Run Code Online (Sandbox Code Playgroud)
我有一个包含以下ConfigurationSection的类:
namespace DummyConsole {
class TestingComponentSettings: ConfigurationSection {
[ConfigurationProperty("waitForTimeSeconds", IsRequired=true)]
[IntegerValidator(MinValue = 1, MaxValue = 100, ExcludeRange = false)]
public int WaitForTimeSeconds
{
get { return (int)this["waitForTimeSeconds"]; }
set { this["waitForTimeSeconds"] = value; }
}
[ConfigurationProperty("loginPage", IsRequired = true, IsKey=false)]
public string LoginPage
{
get { return (string)this["loginPage"]; }
set { this["loginPage"] = value; }
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后我在.config文件中有以下内容:
<configSections>
<section name="TestingComponentSettings"
type="DummyConsole.TestingComponentSettings, DummyConsole"/>
</configSections>
<TestingComponentSettings waitForTimeSeconds="20" loginPage="myPage" />
Run Code Online (Sandbox Code Playgroud)
当我然后尝试使用此配置部分时,我收到以下错误:
var Testing = ConfigurationManager.GetSection("TestingComponentSettings")
as TestingComponentSettings;
Run Code Online (Sandbox Code Playgroud)
ConfigurationErrorsException未处理
属性"waitForTimeSeconds"的值无效.错误是:该值必须在1-100范围内. …
我们的构建服务器仅配置了MS Build Tools 2015,以确保我们已经安装足够的东西来构建项目而无需安装太多(即完整的VS Developer Environment导致过去的部署问题).
我们现在想开始在这个服务器上构建Azure项目,但选项似乎是"包括Visual Studio实例在内的一切",或" 全部或部分这些位 ":
显然我可能不需要模拟器......
我想跟踪我网站的访问者数量.
我在Global.asax类中尝试了以下代码,
<script runat="server">
public static int count = 0;
void Application_Start(object sender, EventArgs e)
{
Application["myCount"] = count;
}
void Session_Start(object sender, EventArgs e)
{
count = Convert.ToInt32(Application["myCount"]);
Application["myCount"] = count + 1;
}
</script>
Run Code Online (Sandbox Code Playgroud)
我正在检索aspx页面中的值,如下所示:
protected void Page_Load(object sender, EventArgs e)
{
int a;
a = Convert.ToInt32((Application["myCount"]));
Label4.Text = Convert.ToString(a);
if (a < 10)
Label4.Text = "000" + Label4.Text ;
else if(a<100)
Label4.Text = "00" + Label4.Text;
else if(a<1000)
Label4.Text = "0" + Label4.Text;
}
Run Code Online (Sandbox Code Playgroud)
上面的编码工作正常.它正确生成访问者,但问题是当我重新启动系统时,count变量再次从0开始,这在逻辑上是错误的.
我希望count的值从最后一个计数值增加1.
那么有人能告诉我如何完成这项任务吗? …
我收到记录器值不能为空。我正在尝试解决这个问题,也许是依赖注入。在单元测试和程序中的其他任何地方都会收到错误。我进行依赖注入正确吗?
Expected: <System.ArgumentException>
But was: <System.ArgumentNullException: Value cannot be null.
Parameter name: logger
at Microsoft.Extensions.Logging.LoggerExtensions.Log(ILogger logger,
LogLevel logLevel, EventId eventId, Exception exception,
String message, Object[] args)
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
using System;
using ElectronicsStore.Models;
using Microsoft.Extensions.Logging;
namespace ElectronicsStore.Service
{
public class ParseVendorSupply
{
private readonly ILogger _logger;
public ParseVendorSupply(ILogger logger)
{
_logger = logger;
}
public VendorSupply FromCsv(string csvLine)
{
VendorSupply vendorsupply = new VendorSupply();
try
{
string[] values = csvLine.Split(',');
if (values.Length > 3)
{
throw new System.ArgumentException("Too much data");
}
vendorsupply.VendorId …Run Code Online (Sandbox Code Playgroud) asp.net ×4
asp.net-mvc ×3
c# ×3
msbuild ×2
.net ×1
asp.net-core ×1
azure ×1
build-server ×1
jquery ×1
linq ×1
logging ×1
nant ×1
nunit ×1
sitecore ×1
teamcity ×1
validation ×1