小编dan*_*sky的帖子

比较C#中两个DateTime的相等性的最佳方法是什么?但只有一定的精度?

我有两个日期时间,一个来自时间戳,另一个是我在代码中生成的.我需要测试他们的平等,并且喜欢在没有太多表情的情况下做到这一点.这是我两个日期的一个例子:

DateTime expireTimeStampUTC = 
    DateTime.Parse(UTCValueFromDatabase));
DateTime expectedExpireTime = 
    DateTime.UtcNow.AddHours(NumberOfExpectedHoursInConfig);
Run Code Online (Sandbox Code Playgroud)

这是测试精度太高:

if(expireTimeStampUTC.Equals(expectedExpireTime)){}

我不在乎他们是否与第二小时完全相同.

它可能是做这样复合的最佳解决方案:

if (expireTimeStampUTC.Date.Equals(expectedExpireTime.Date))
{
    if (!expireTimeStampUTC.Hour.Equals(expectedExpireTime.Hour))
    {
        pass = false;
    }
}
Run Code Online (Sandbox Code Playgroud)

我不是最有经验的C#...是否有一些优雅的方法来做到这一点?

c# datetime date

6
推荐指数
2
解决办法
3993
查看次数

通过HTTP发送Web表单身份验证数据的最佳方法是什么?

我所知道的一家公司正在讨论如何在其所有Web应用程序产品中确定其密码安全策略.

现在,他们通过HTTP在POST表单中发送用户名/密码身份验证,因此,他们正在发送纯文本.

解决这个问题最简单的方法就是要求HTTPS在所有应用程序中登录,对吧?

好吧,有一些内部讨论,而不是做一些自己的客户端密码加密(密码+盐等).

是否有可接受的仅HTTP解决方案?

意见就像......好吧,每个人都有意见,所以我正在寻找可以支持你的建议的可靠安全文献.不要只是google并将我发送到博客文章......我已经做到了这一点.

我找到了OWASP的建议:http: //www.owasp.org/index.php/Top_10_2007-A7#Protection

以及微软的:http: //msdn.microsoft.com/en-us/library/aa302420.aspx

编辑:提供使用SSL的建议是不够​​的.我需要某种支持文档.我知道滚动我们自己的客户端加密是不好的.我需要能够可靠地将其出售给同事和管理层.

此外,还提到了HTTP Digest.看起来不错,但Digest仅用于HTTP身份验证,而不适用于通过POST发送的数据.

security https http owasp

6
推荐指数
3
解决办法
1456
查看次数

如何构建C#控制台应用程序以有效使用IDisposable数据库资源?

这是我为C#控制台应用程序设计的(非常简化以说明问题空间)设计.数据库连接实现IDisposable,此解决方案不允许using数据库连接对象.有人可以为控制台应用程序提出更正确的结构吗?这是我经常需要解决的问题.

class Program 
{
    SQLiteConnection sourceConnection;
    SQLiteConnection destinationConnection;

    static void Main(string[] args)
    {
        Program shell = new Program();

        // get connection strings from command line arguments
        string sourceConnectionString = shell.getConnectionString(args);
        string destinationConnectionString = shell.getConnectionString(args);

        // call non-static methods that use
        shell.setUpConnections(sourceConnectionString, destinationConnectionString);

        shell.doDatabaseWork();
    }

    private void setUpConnections(string sourceConnectionString, string destinationConnectionString)
    {
        sourceConnection = new SQLiteConnection(sourceConnectionString);
        destinationConnection = new SQLiteConnection(destinationConnectionString);
    }

    private void doDatabaseWork()
    {
        // use the connections here
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:

有些人无法弄清楚为什么我要将它们作为成员变量.这是doDatabaseWork中的用例(有点伪问题):

foreach (Row sourceRow in DBResultSet) …
Run Code Online (Sandbox Code Playgroud)

c# sqlite database-connection console-application

5
推荐指数
2
解决办法
1万
查看次数

如何在写入单个Samba共享时设置Samba保留文件所有权?

我想通过samba共享在我的linux机器上编辑Solr配置文件.文件需要tomcat6:mygroup,但是当我通过Windows编辑文件时,它会将它们写为myuser:mygroup.是否可以更改单个samba共享的写入设置,以便保留现有用户,组和权限?

这可以通过Samba配置完成,还是需要更复杂的东西?

linux samba

1
推荐指数
1
解决办法
2742
查看次数

为什么以下JSON无效?

以下JSON未通过验证.验证器在第一个字符串值处开始抱怨"Can an officer...

它看起来像是键的有效字符串值的开头.究竟是什么问题呢?

{
   "DUI": {
      "Can an officer arrest me because he smelled alcohol on my breath?":"<br />No, odor alone is not sufficient basis for arrest. However, odor combined with other observations such as weaving, slurred speech, and bloodshot eyes 
may be enough to give an officer probable cause to arrest you for DUI.",
      "Can I be convicted if I refused to take the breath test or the result was below .08?":"<br />Yes, in Washington the prosecutor …
Run Code Online (Sandbox Code Playgroud)

json

1
推荐指数
1
解决办法
5318
查看次数