我正在使用WPF DataGrid
(Toolkit中的.Net 3.5 SP 1版本)
我可以订阅什么事件来检测何时添加新行?(例如,当用户向下移动光标或按Enter键时,新的空白行将添加到网格中).
最终我想要做的是使用该事件来计算一些默认值并将它们放在新行中.
网格绑定到a DataTable
,如果这有任何区别.
我的Feed的内容类型有问题:
当我设置content-type
到"application/rss+xml"
或"application/atom+xml"
将火狐将使其电流(并显示默认订阅页),但Chrome的渲染它"text/plain"
.当我更改content-type
为"text/xml"
或"application/xml"
同时Firefox和Chrome将其呈现为xml文档时(Firefox将不会显示"订阅"页面).
你有什么想法或建议吗?我应该为rss.xml和atom.xml使用哪种内容类型?
我Microsoft.Owin.Security
在我的应用程序中使用(.NET 4.5上的ASP.NET MVC v 5.2.0).但只是安全部分OWIN
没有别的.当用户想要访问本地受保护的URL时,请求将被重定向到登录页面.但是当我在服务器上发布应用程序时,我得到这个窗口而不是重定向:
我的登录和注销方法是:
public void LogIn(long userId, string username, string email, bool persistent) {
var claims = new List<Claim>{
new Claim(ClaimTypes.NameIdentifier, userId.ToString(CultureInfo.InvariantCulture)),
new Claim(ClaimTypes.Name, username),
new Claim(ClaimTypes.Email, email),
new Claim(ClaimTypes.IsPersistent, persistent.ToString())
};
var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
var ctx = HttpContext.Current.Request.GetOwinContext();
var authenticationManager = ctx.Authentication;
authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
authenticationManager.SignIn(new AuthenticationProperties {
IsPersistent = persistent
}, id);
}
public void LogOut() {
var ctx = HttpContext.Current.Request.GetOwinContext();
var authenticationManager = ctx.Authentication;
authenticationManager.SignOut();
}
Run Code Online (Sandbox Code Playgroud)
这是我的创业公司:
public partial …
Run Code Online (Sandbox Code Playgroud) 我在C#和JAVA之间进行通讯时遇到问题。我必须使用JAVA中的SHA1对程序中的值进行哈希处理。问题是,在计算哈希JAVA结果(这样做的C# ,但:) 式JAVA的签署,而它的无符号在C# 。因此,我必须摆脱JAVA中的多余位(无法触摸C#端)。这是我在做什么:byte[]
byte
private static int[] Hash(byte[] plainBytes, byte[] saltBytes)
throws NoSuchAlgorithmException, UnsupportedEncodingException {
byte[] sourceBytes = new byte[plainBytes.length + saltBytes.length];
for (int i = 0, il = plainBytes.length; i < il; i++)
sourceBytes[i] = plainBytes[i];
for (int i = 0, il = saltBytes.length, pil = plainBytes.length; i < il; i++)
sourceBytes[pil + i] = saltBytes[i]; …
Run Code Online (Sandbox Code Playgroud) 在ASP.NET Core(v 2.1.5)中,您可以创建控制器,而无需从Controller
类继承(如您所知).如果你这样做,你必须RouteAttribute
用来定义你的路线.但是,如果我们可以将隐式路由(而不是属性路由)与ApiController
属性一起使用,我感兴趣.示例:具有此隐式路由Startup.cs
:
app.UseMvc(routeBuilder =>
{
routeBuilder.MapRoute("api_default", "{controller}/{action}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)
还有这个 Cotroller
[ApiController]
public class ValuesController
{
[HttpGet]
public string Get(int id) => id.ToString();
}
Run Code Online (Sandbox Code Playgroud)
将抛出此异常:
InvalidOperationException:Action'TestApi.Controllers.ValuesController.Get'没有属性路由.使用ApiControllerAttribute注释的控制器上的操作方法必须是属性路由.
有没有办法避免异常?
c# attributerouting .net-core asp.net-core asp.net-core-webapi
这个问题很清楚。在其生命周期中是否DbContext
保持开放连接?EF 核心怎么样?
在.NET Razor Web应用程序中,我正在尝试以编程方式设置Layout
.我不能使用_ViewStart.cshtml
,也不会@{ Layout = "..." }
在每个页面上设置.这就是我想出的:
基WebViewPage
类:
public abstract class SitePage<T> : System.Web.Mvc.WebViewPage<T>
{
private object _layout;
public new dynamic Layout { get { return _layout; } }
public override void InitHelpers()
{
base.InitHelpers();
_layout = "~/Themes/" + Settings.Theme + "/Views/_Layout.cshtml";
}
}
Run Code Online (Sandbox Code Playgroud)
在应用程序中,web.config
我指定所有视图以使用此基页.但Layout
似乎从未使用过.这可能有什么问题?
我昨天在这里问了一个关于从匿名对象读取属性并将它们写入类的私有字段的问题。问题解决了。这是一个简短的故事:
我有一些json格式的数据。我将它们反序列化为ExpandoObject
,并将它们作为IDictionary<string, object>
to 方法传递。它工作正常,除了Int32
属性。似乎他们变成了Int64
,在哪里?我不知道。
这里又是方法:
private Func<IDictionary<string, object>, dynamic> MakeCreator(
Type type, Expression ctor,
IEnumerable<PropertyToFieldMapper> maps) {
var list = new List<Expression>();
var vList = new List<ParameterExpression>();
// creating new target
var targetVariable = Expression.Variable(type, "targetVariable");
vList.Add(targetVariable);
list.Add(Expression.Assign(targetVariable, Expression.Convert(ctor, type)));
// accessing source
var sourceType = typeof(IDictionary<string, object>);
var sourceParameter = Expression.Parameter(sourceType, "sourceParameter");
// calling source ContainsKey(string) method
var containsKeyMethodInfo = sourceType.GetMethod("ContainsKey", new[] { typeof(string) });
var accessSourceIndexerProp = sourceType.GetProperty("Item"); …
Run Code Online (Sandbox Code Playgroud) 我正在WPF
使用这些软件包开发一个项目:
<package id="Autofac" version="3.0.2" targetFramework="net40" />
<package id="Caliburn.Micro" version="1.5.1" targetFramework="net40" />
<package id="Caliburn.Micro.Autofac" version="1.5.0" targetFramework="net40" />
Run Code Online (Sandbox Code Playgroud)
直到昨天我将包更新到:
<package id="Autofac" version="3.1.1" targetFramework="net40" />
<package id="Caliburn.Micro" version="1.5.2" targetFramework="net40" />
<package id="Caliburn.Micro.Autofac" version="1.5.0" targetFramework="net40" />
Run Code Online (Sandbox Code Playgroud)
我的意思是,我更新Autofac
从3.0.2
到3.1.1
和Caliburn.Micro
从1.5.1
到1.5.2
(使用Nuget Package Manager
).在那之后,我无法运行该项目.我收到此错误:
'在类型'MyAppBootstrapper'上调用与指定绑定约束匹配的构造函数会引发异常.行号'9'和行位置'22'.
在这一行App.xaml
:
内部异常消息是:
{"未找到方法:'Void Caliburn.Micro.Bootstrapper`1..ctor(Boolean)'."}
升级是否有任何意义我错过了?
完整的堆栈跟踪:
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, …
Run Code Online (Sandbox Code Playgroud) 我定义了这个简单的类型:
public struct Price : IComparer<Price>, IEquatable<Price> {
private readonly decimal _value;
public Price(Price value) {
_value = value._value;
}
public Price(decimal value) {
_value = value;
}
public int Compare(Price x, Price y) {
return x._value.CompareTo(y._value);
}
public int Compare(Price x, decimal y) {
return x._value.CompareTo(y);
}
public int Compare(decimal x, Price y) {
return x.CompareTo(y._value);
}
public bool Equals(Price other) {
return _value.Equals(other._value);
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj))
return false;
return obj is …
Run Code Online (Sandbox Code Playgroud) c# ×6
wpf ×2
.net-core ×1
asp.net-core ×1
asp.net-mvc ×1
atom-feed ×1
autofac ×1
base64 ×1
bytearray ×1
content-type ×1
datagrid ×1
dbconnection ×1
expression ×1
firefox ×1
iis ×1
java ×1
json ×1
lambda ×1
layout ×1
lifecycle ×1
owin ×1
razor ×1
reflection ×1
rss ×1
sha1 ×1
wpf-4.0 ×1