通过WebDeploy将.Net Core应用发布到服务器时,将使用创建一个Web.Config文件stdoutLogEnabled=false。这将覆盖我设置的服务器上的web.config stdoutLogEnabled=true。
我努力寻找如何设置stdoutLogEnabled发布前的默认值。在.Net framework应用程序上,我会在web.config文件中进行转换,但是,在.Net core中,我的解决方案中实际上没有web.config文件。
我试图找到有关如何设置该值的文档,但是它不存在,或更可能是我没有使用正确的搜索词。有人可以建议如何在web.config中设置默认值。
我正在为视图模型创建自定义模型活页夹,实现 IModelBinder
我的视图模型中有很多属性,其中大多数不需要任何自定义绑定。与其从单独显式设置模型上的所有属性值,不如让ModelBindingContext我能够获得为我绑定模型的框架,然后执行任何自定义绑定:
public class ApplicationViewModelBinder : IModelBinder
{
public Task BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
// get .net core to bind values on model
// Cary out any customization of the models properties
bindingContext.Result = ModelBindingResult.Success(bindingContext.Model);
return Task.CompletedTask;
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,我想执行默认的模型绑定,然后应用自定义绑定,类似于本SO帖子中采用的方法,但适用于.NET Core,而不是框架。
我以为应用默认绑定会很简单,但是还没有找到方法。我相信该解决方案将涉及ComplexTypeModelBinder和ComplexTypeModelBinderProvider类,但似乎无法找出解决方法。
我知道我可以在POST请求命中我的控制器方法时进行任何更改,但这似乎是错误的位置和错误的时间。
defaultmodelbinder model-binding custom-model-binder asp.net-core-mvc asp.net-core
是否可以在ghci.conf文件中设置别名?
例如我alias sbh='cd Desktop/Sandbox/Haskell'在bash.bashrc中,它让我快速跳转到指定的文件夹.通过在ghci.conf文件中添加别名,可以在ghci中做同样的事情吗?
我已经在ghci.conf中有一些命令但是我想设置多个别名来跳转到文件夹位置而不必一直使用:cd home/sandbox/foo/bar.我无法在谷歌上找到任何东西,所以要么以前从未考虑过,要么只是遗漏了一些非常简单的东西.
我正在努力解决Haskell中的Project Euler问题.我已经得到了下面的问题3的解决方案,我已经在小数字上进行了测试并且它可以正常工作,但是由于通过首先导出所有素数数字来实现蛮力,所以对于较大的数字它是指数级慢的.
-- Project Euler 3
module Main
where
import System.IO
import Data.List
main = do
hSetBuffering stdin LineBuffering
putStrLn "This program returns the prime factors of a given integer"
putStrLn "Please enter a number"
nums <- getPrimes
putStrLn "The prime factors are: "
print (sort nums)
getPrimes = do
userNum <- getLine
let n = read userNum :: Int
let xs = [2..n]
return $ getFactors n (primeGen xs)
--primeGen :: (Integral a) => [a] -> [a]
primeGen [] …Run Code Online (Sandbox Code Playgroud) 我有一个 C# 解决方案,其中包含两个项目 ProductStore.Web 和 ProductStore.Data,它们都针对 .NET Core 2.0。
我有我的 HomeController 和 CustomerRepository 如下(我已经在 HomeController 中设置它以提高速度,客户创建将在客户控制器中,但还没有脚手架出来):
namespace ProductStore.Web.Controllers
{
public class HomeController : Controller
{
private readonly DatabaseContext _context;
public HomeController(DatabaseContext context)
{
_context = context;
}
public IActionResult Index()
{
ICustomerRepository<Customer> cr = new CustomerRepository(_context);
Customer customer = new Customer
{
// customer details
};
//_context.Customers.Add(customer);
int result = cr.Create(customer).Result;
return View();
}
}
}
namespace ProductStore.Data
{
public class CustomerRepository : ICustomerRepository<Customer>
{
DatabaseContext _context;
public CustomerRepository(DatabaseContext context) …Run Code Online (Sandbox Code Playgroud) asp.net-mvc dependency-injection entity-framework-6 asp.net-core asp.net-core-2.0
我目前在下面有Haskell函数,它将整数转换为从原始整数中取得的数字列表.我的问题是:有没有办法在不使用mod和的情况下做到这一点div?例如,如果我想用字符串做同样的事情,我可以创建一个利用其他功能的功能,如头部和尾部等.
我在这个问题上挣扎了一段时间才终于来到SO并在另一篇文章中找到答案.是什么让我问这个问题的事实是我从来没有想过使用mod和div我自己!
toDigits :: Integer -> [Integer]
toDigits n
| n < 1 = []
| otherwise = toDigits (n `div` 10) ++ [n `mod` 10]
Run Code Online (Sandbox Code Playgroud) 通过Project Euler我将我的解决方案与这里的解决方案进行比较.
对于问题8,我的代码产生正确的答案(通过网站上的校验金确认)23514624000.
module Main where
import Data.List
main = do
print $ last (sort eulerEight)
eulerEight = doCalc [ x | x <- toDigits 7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450]
where
doCalc (_:[]) = []
doCalc (x:xs) = if 0 `notElem` take 13 (x:xs) && length (x:xs) > 12
then product (take 13 (x:xs)) : doCalc xs
else doCalc xs
toDigits n
| n < 1 = []
| otherwise = toDigits (n `div` 10) ++ [n `mod` 10]
Run Code Online (Sandbox Code Playgroud)
我意识到这可能要好得多,所以在这里检查解决方案并且它似乎不正确. …
我刚接触C++编程,但有一些Java经验.我创建了一个非常基本的类Dog.cpp及其头文件Dog.hpp.Netbeans不会构建项目,给我一个错误,说明构造函数和getAge函数的多个定义.就我而言,我已经在头文件中声明了构造函数和函数,并在类文件中定义它们.我哪里出错了?
提前致谢!
Dog.hpp:
#include <iostream>
using namespace std;
class Dog
{
public:
Dog(int someAge); // Constructor
~Dog(); // Destructor
int getAge() const; // function prototype
private:
int itsAge; // age variable
};
Run Code Online (Sandbox Code Playgroud)
Dog.cpp:
#include "Dog.hpp"
using namespace std;
Dog::Dog(int anAge)
{
cout << "Dog created \n";
}
int Dog::getAge() const
{
return itsAge;
}
Run Code Online (Sandbox Code Playgroud)
**main.cpp
#include <iostream>
#include "Dog.cpp"
int main()
{
Dog aDog(5);
cout << aDog.getAge();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Netbeans输出:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory …Run Code Online (Sandbox Code Playgroud) 我对Haskell相对较新(第三天学习语言)并且遇到模式匹配问题.我已经定义了doubleEveryOther下面的函数,据我所知,我已经涵盖了三种可能的场景:空列表,长度列表== 1和列表长度> 1.代码编译好但是当尝试使用它抛出的函数时非穷举模式匹配错误:
*** Exception: ex2.hs:(3,1)-(5,55): Non-exhaustive patterns in function doubleEveryOther
Run Code Online (Sandbox Code Playgroud)
然后我在GHCI中启用了警告,并在加载ex2.hs文件时发现以下警告:
ex2.hs:3:1: Warning:
Pattern match(es) are non-exhaustive
In an equation for `doubleEveryOther':
Patterns not matched: _ : (_ : (_ : _))
Run Code Online (Sandbox Code Playgroud)
第3行:1指的是我认为已经覆盖的空壳 doubleEveryOther [] = []
我不知道我在哪里出错了.帮助赞赏.
干杯,
-- file: ex2.hs
doubleEveryOther :: [Integer] -> [Integer]
doubleEveryOther [] = []
doubleEveryOther (x:[]) = [x]
doubleEveryOther (_:[xs]) = take (length [xs] - 1) [xs]
Run Code Online (Sandbox Code Playgroud) 我一直在尝试通过 Team City 构建和发布 MSBuild 时遇到问题。收到的错误信息如下:
C:\Program Files\dotnet\sdk\2.2.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(208, 5): error NETSDK1047: Assets file 'F:\TeamCity\buildAgent\work\9f1e0cb4e5e5076f\myproject\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.2/win-x64'. Ensure that restore has run and that you have included 'netcoreapp2.2' in the TargetFrameworks for your project. You may also need to include 'win-x64' in your project's RuntimeIdentifiers.
Run Code Online (Sandbox Code Playgroud)
我原以为将参数中的以下内容传递给 MSBuild 应该可以解决问题。
/p:TargetFramework=netcoreapp2.2 /p:Runtimeidentifier=win-x64
Run Code Online (Sandbox Code Playgroud)
然而事实并非如此。
我可以从 Visual Studio 中构建/发布项目,但不能通过 Team City 构建代理。
为了让构建代理构建/发布,我必须在项目 .csproj 文件中声明运行时标识符:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
在我看来,要么 Team City 忽略了 MSBuild 参数,我的参数不正确,要么 Visual Studio 正在执行一个我不知道的附加步骤,以在发布时声明运行时标识符(通过 WebDeploy)。
我显然已经解决了我遇到的问题,但这似乎不是“正确”的做法。我错过了什么?
谢谢,
我目前正在学习Haskell(我的问题很多都是从最近的这个声明开始)而且由于语法错误而导致编译程序的问题,主要是识别错误,理解/解决GHC提供的错误消息.
例如,它只是花了我很长时间来解决下面代码中的错误.请记住,这是从Haskell教程书中获取的:
getNums = do
putStrLn "enter a number (0 to terminate)"
num <- getLine
if read num == 0
then return []
else do rest <- getNums
return ((read num :: Int):rest)
Run Code Online (Sandbox Code Playgroud)
GHCI输出错误消息也没有真正帮助:
Number.hs:18:17:
The last statement in a 'do' block must be an expression
rest <- getNums
Run Code Online (Sandbox Code Playgroud)
我目前正在通过Linux终端运行GHCI并手动编译,用gedit编写的代码.我的问题是:
是否有更好的环境或设置可以为像我这样的初学者提供更深入的编译时错误解释?
即类似于NetBeans IDE将提供关于为什么代码在语法上不正确的提示/提示的方式?
我要做的最后一件事就是在SO上粘贴一个代码块,并且是那个说"为我解决这个问题"的白痴
编辑
我很欣赏这可能不被归类为一个非常好的问题,因为它基本上要求人们提出意见.
haskell ×6
asp.net-core ×4
ghci ×2
msbuild ×2
alias ×1
asp.net-mvc ×1
c++ ×1
ghc ×1
pointfree ×1
primes ×1
teamcity ×1
terminal ×1
web-config ×1