我有一个Visual Studio Web应用程序项目,由于某些原因,将文件从多个项目复制到单独的输出目录.我想将此输出目录用作关联的IIS Express站点的根目录.在IIS Express的applicationhost.config文件中,我可以将关联站点的物理路径设置为正确的目录.我会这样设置:
<site name="MySiteName" id="42">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="c:\my\desired\path" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:63470:localhost" />
</bindings>
</site>
Run Code Online (Sandbox Code Playgroud)
但是,当我重新打开项目时,Visual Studio会覆盖我指定的物理路径,将其还原到项目自己的目录.更糟糕的是,Visual Studio没有表明它已经做到了这一点.以下是<virtualDirectory>Visual Studio混淆后元素的外观:
<virtualDirectory path="/" physicalPath="c:\path\to\project" />
Run Code Online (Sandbox Code Playgroud)
如何防止Visual Studio覆盖此路径?
RestSharp的内置JSON序列化程序序列化了对象的所有属性,即使它们为null或者是默认值.如何让它跳过这些属性?
我在WPF中使用MVVM模式并遇到了一个问题,我可以将其简化为以下内容:
我有一个CardType模型.
public class CardType
{
public int Id { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有一个使用CardType的viewmodel.
public class ViewModel : INotifyPropertyChanged
{
private CardType selectedCardType;
public CardType SelectedCardType
{
get { return selectedCardType; }
set
{
selectedCardType = value;
OnPropertyChanged(nameof(SelectedCardType));
}
}
public IEnumerable<CardType> CardTypes { get; set; }
// ... and so on ...
}
Run Code Online (Sandbox Code Playgroud)
我的XAML有一个ComboBox,它的项目基于CardTypes,应该根据SelectedCardType预选一个项目.
<ComboBox ItemsSource="{Binding CardTypes}"
DisplayMemberPath="Name"
SelectedItem="{Binding SelectedCardType}"/>
Run Code Online (Sandbox Code Playgroud)
由于我无法控制的原因,SelectedCardType对象将是CardTypes中项目的引用不等份副本.因此,WPF无法将SelectedItem与ItemsSource中的项匹配,当我运行应用程序时,ComboBox最初显示时未选中任何项.
我尝试覆盖CardType上的Equals()和GetHashCode()方法,但WPF仍然无法匹配项目.
鉴于我特有的限制,我如何让ComboBox选择正确的项目?
我的Web应用程序项目包含在单个IIS Express站点的保护下提供的多个Web站点.我成功地遵循了Scott Hanselman的优秀博客文章,并且IIS Express成功地从同一个Web应用程序根目录提供了http://foo.local和http://bar.local.
但是,我需要两个站点都支持SSL.根据Hanselman的建议,我可以创建一个SSL证书并将其"附加"到一个IP端口组合.
makecert -r -pe -n "CN=foo.local" -b 01/01/2000 -e 01/01/2036 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12
netsh http add sslcert ipport=0.0.0.0:443 appid='{214124cd-d05b-4309-9af9-9caa44b2b74b}' certhash=284475d4a4eb5c4d3ab7da4fdefa928186482376
Run Code Online (Sandbox Code Playgroud)
这成功了,但我无法重复第二个站点的过程.显然,只有一个SSL证书可以应用于单个IP端口组合.
如何制作涵盖https://foo.local和https://bar.local的SSL证书,或以其他方式为每个站点"附加"一个?
我正在尝试创建最简单的ASP.NET 5项目来提供静态文件,而不依赖于Visual Studio项目模板.但是,当我请求一个文件时,我只收到一个空的响应.这是我的代码:
project.json:
{
"wwwroot": "wwwroot",
"dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta8"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnx46": { }
}
}
Run Code Online (Sandbox Code Playgroud)
Startup.cs:
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
namespace Study.StaticFileServer
{
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
}
}
}
Run Code Online (Sandbox Code Playgroud)
最后,有一个包含"downloadme.txt"的"wwwroot"文件夹.
当我运行dnx web并请求文件时,响应为空.为了让这个工作,我必须添加什么?
我正在使用knockout.js构建<select>元素的<option>s,并设置其默认选择的值.在我添加optionsValue绑定之前,所有工作都按预期工作,此时下拉列表不再显示页面加载时的正确初始值.
换句话说,这有效:
<select data-bind="value: selectedAccount, options: accounts, optionsText: 'name'"></select>
Run Code Online (Sandbox Code Playgroud)
...但这不起作用:
<select data-bind="value: selectedAccount, options: accounts, optionsText: 'name', optionsValue: 'id'"></select>
Run Code Online (Sandbox Code Playgroud)
这是我简化的完整代码:
<!doctype html>
<html>
<head>
<title>Demo</title>
<script src='knockout-2.1.0.debug.js'></script>
</head>
<body>
<select data-bind="value: selectedAccount, options: accounts, optionsText: 'name', optionsValue: 'id'"></select>
<script>
function QuickTransferViewmodel()
{
var self = this;
self.accounts =
[
{ id: 0, name: "Spending" },
{ id: 1, name: "Savings" }
];
self.selectedAccount = ko.observable(self.accounts[1]);
}
ko.applyBindings(new QuickTransferViewmodel());
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我希望下拉列表默认显示"Savings".只有删除optionsValue绑定才会这样做. …
我想使用.NET CoreCLR运行一个hello-world控制台应用程序.
到目前为止,我的代码如下.
// Program.cs
using System;
namespace Study
{
public class Program
{
public void Main()
{
Console.WriteLine("Hello world!");
}
}
}
Run Code Online (Sandbox Code Playgroud)
// project.json
{
"frameworks": {
"dnxcore50": { }
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用命令运行此项目:
dnvm use 1.0.0-beta8 -r coreclr
dnx run
Run Code Online (Sandbox Code Playgroud)
但是,这会产生以下错误:
Microsoft.Dnx.Compilation.CSharp.RoslynCompilationException: warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options.
(1,11): DNXCore,Version=v5.0 error CS0246: The type or namespace name 'System' could not be found …Run Code Online (Sandbox Code Playgroud) iis-express ×2
.net ×1
asp.net-core ×1
binding ×1
combobox ×1
coreclr ×1
data-binding ×1
default ×1
https ×1
json ×1
knockout.js ×1
makecert ×1
mvvm ×1
netsh ×1
options ×1
restsharp ×1
select ×1
ssl ×1
static-files ×1
wpf ×1
xaml ×1