我有一个需要非常安全的 Web 应用程序。我已经阅读了 IdentityServer4 概述。我不明白在什么情况下我需要使用它。如果有人能澄清,我将不胜感激。提前致谢!
我以为我试图做一些非常简单的事情.我只想在屏幕上报告一个正在运行的号码,以便用户知道我正在执行的SQL存储过程正在运行,并且他们没有耐心并开始点击按钮.
问题是我无法弄清楚如何实际调用ExecutNonQueryAsync命令的进度报告器.它停留在我的报告循环中并且从不执行命令但是,如果我把它放在async命令之后,它将被执行并且结果永远不会等于零.
任何想法,评论,想法将不胜感激.非常感谢!
int i = 0;
lblProcessing.Text = "Transactions " + i.ToString();
int result = 0;
while (result==0)
{
i++;
if (i % 500 == 0)
{
lblProcessing.Text = "Transactions " + i.ToString();
lblProcessing.Refresh();
}
}
// Yes - I know - the code never gets here - that is the problem!
result = await cmd.ExecuteNonQueryAsync();
Run Code Online (Sandbox Code Playgroud) 我已经看过这些例子,但我希望其他程序员可以运行它.对于我的窗体表单应用程序中的加密,我生成两个随机数并将它们保存在SQL Server表中,如下所示:
OPEN SYMMETRIC KEY SymmetricKeyName DECRYPTION BY CERTIFICATE CertificateName;
insert into keyfile(encrypted_key1, encrypted_key2) values
(EncryptByKey(Key_GUID('SymmetricKeyName'), **Key1**),
EncryptByKey(Key_GUID('SymmetricKeyName'), **Key2**))
Run Code Online (Sandbox Code Playgroud)
然后我使用密钥使用AES-256加密文件,如下所示:
var key = new Rfc2898DeriveBytes(**Key1, Key2**, 1000);
RijndaelManaged AES = new RijndaelManaged();
AES.KeySize = 256;
AES.BlockSize = 128;
AES.Key = key.GetBytes(AES.KeySize / 8);
AES.IV = key.GetBytes(AES.BlockSize / 8);
AES.Padding = PaddingMode.Zeros;
AES.Mode = CipherMode.CBC;
using (var output = File.Create(outputFile))
{
using (var crypto = new CryptoStream(output, AES.CreateEncryptor(), CryptoStreamMode.Write))
{
using (var input = File.OpenRead(inputFile))
{
input.CopyTo(crypto);
}
}
}
etc. …Run Code Online (Sandbox Code Playgroud) 我正在使用Visual Studio,我对存储配置字符串的最佳方法感到困惑.我正在创建一个Windows窗体应用程序.我需要非常基本的安全性 - 我不希望密码在app.config中可读,但我并不担心有人为了解决这个问题而反汇编我的代码.
因此,在数据源向导中,我说"不保存密码",然后我将以下代码放在Settings.Designer.CS中:
public string MyConnectionString {
get {
return ((string)("Data Source=SQLSERVER\\ACCOUNTING;Initial Catalog=ACCOUNTING;User ID=MyUser;Password=28947239SKJFKJF"));
}
}
Run Code Online (Sandbox Code Playgroud)
我意识到这不是最好的解决方案,但我想不出更好的解决方案.我很感激任何人的帮助和意见.
谢谢 -
大小姐.
我有加密方法,运行缓慢.加密数百MB的数据大约需要20分钟.我不确定我是否采取了正确的方法.任何帮助,想法,建议将不胜感激.
private void AES_Encrypt(string inputFile, string outputFile, byte[] passwordBytes, byte[] saltBytes)
{
FileStream fsCrypt = new FileStream(outputFile, FileMode.Create);
RijndaelManaged AES = new RijndaelManaged();
AES.KeySize = 256;
AES.BlockSize = 128;
var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
AES.Key = key.GetBytes(AES.KeySize / 8);
AES.IV = key.GetBytes(AES.BlockSize / 8);
AES.Padding = PaddingMode.Zeros;
AES.Mode = CipherMode.CBC;
CryptoStream cs = new CryptoStream(fsCrypt,
AES.CreateEncryptor(),
CryptoStreamMode.Write);
FileStream fsIn = new FileStream(inputFile, FileMode.Open);
int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);
fsCrypt.Flush();
cs.Flush();
fsIn.Flush();
fsIn.Close();
cs.Close();
fsCrypt.Close(); …Run Code Online (Sandbox Code Playgroud) 我正在使用Quartz并使用示例代码并得到以下错误:
CS0738'EmailJob'未实现接口member
IJob.Execute(IJobExecutionContext)。EmailJob.Execute(IJobExecutionContext)无法实现,IJob.Execute(IJobExecutionContext)因为它>没有匹配的返回类型Task。
这是我第一次来Quartz,所以任何帮助将不胜感激。
public class EmailJob : IJob // <<<--- Error on this line
{
public void Execute(IJobExecutionContext context)
{
using (var message = new MailMessage("user@gmail.com", "user@live.co.uk"))
{
message.Subject = "Test";
message.Body = "Test at " + DateTime.Now;
using (SmtpClient client = new SmtpClient
{
EnableSsl = true,
Host = "smtp.gmail.com",
Port = 587,
Credentials = new NetworkCredential("user@gmail.com", "password")
})
{
client.Send(message);
}
}
}
public class JobScheduler
{
public static void …Run Code Online (Sandbox Code Playgroud) 我有一个C#WPF程序打开一个文件,逐行读取,操纵每一行然后将该行写入另一个文件.那部分工作正常.我想添加一些进度报告,因此我将方法设为异步并使用等待进度报告.进度报告非常简单 - 只需更新屏幕上的标签即可.这是我的代码:
async void Button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Title = "Select File to Process";
openFileDialog.ShowDialog();
lblWaiting.Content = "Please wait!";
var progress = new Progress<int>(value => { lblWaiting.Content = "Waiting "+ value.ToString(); });
string newFN = await FileProcessor(openFileDialog.FileName, progress);
MessageBox.Show("New File Name " + newFN);
}
static async private Task<string> FileProcessor(string fn, IProgress<int> progress)
{
FileInfo fi = new FileInfo(fn);
string newFN = "C:\temp\text.txt";
int i = 0;
using (StreamWriter sw = new StreamWriter(newFN)) …Run Code Online (Sandbox Code Playgroud) 我正在使用这种方法来压缩文件,它工作得很好,直到我得到一个 2.4 GB 的文件,然后它给了我一个溢出错误:
void CompressThis (string inFile, string compressedFileName)
{
FileStream sourceFile = File.OpenRead(inFile);
FileStream destinationFile = File.Create(compressedFileName);
byte[] buffer = new byte[sourceFile.Length];
sourceFile.Read(buffer, 0, buffer.Length);
using (GZipStream output = new GZipStream(destinationFile,
CompressionMode.Compress))
{
output.Write(buffer, 0, buffer.Length);
}
// Close the files.
sourceFile.Close();
destinationFile.Close();
}
Run Code Online (Sandbox Code Playgroud)
我可以做什么来压缩大文件?
需要创建一个带有日期列表的IN子句.列表需要按降序排列.我创建了一个名为@cols的变量,并尝试使用以下代码填充它:
declare @end date='2016/05/30'
declare @begin date = DATEADD(month, DATEDIFF(month, 0, @end), 0) ;
declare @curdate date = @end; -- start on the last day
print @curdate;
print @begin;
DECLARE @cols NVARCHAR (MAX)
while @curdate >=@begin -- goes from end of the month to beginning of the month
begin
select @cols = @cols + ',[' + CONVERT(NVARCHAR, @curdate, 106) + ']';
select @curdate = DATEADD(DAY,-1,@curdate ) -- subtract a day
end
print @cols;
print @curdate;
print @begin;
Run Code Online (Sandbox Code Playgroud)
我希望得到5/30/16,5/29/16,5/28/16等(当然格式正确).代码运行没有错误,但@cols总是为空.
我使用了一些来自互联网的代码来模拟我对存储过程的一些查询。它使用关键字 TAB,我不知道它是做什么的。任何人都可以向我解释这一点吗?
这是代码:
SELECT * INTO #DailyReport
FROM
(SELECT a.customer,b.cust_name, opendt, txdate [DATE], salesamt
from Daily a left outer join customer b on a.customer =b.customer
where txdate between @begin and @end) TAB
SELECT * INTO #DailyTX
FROM
(SELECT customer, txdate [DATE], SALESTX from Daily
where txdate between @begin and @end) TAB
Run Code Online (Sandbox Code Playgroud) 我研究、测试和使用了 RegEx.101,但无法弄清楚这一点。我花了几个小时在上面。
我正在寻找16 位数字。
这是我的正则表达式: "[0-9]{16}"
这是代码:
Regex ItemRegex = new Regex("[0-9]{16}");
// test with a 29 digit number
foreach (Match ItemMatch in ItemRegex.Matches("564654564553314342340968580654"))
{
i++;
}
Run Code Online (Sandbox Code Playgroud)
我期待多个匹配项,但我只得到前 16 位数字。如何获取从位置 1 开始的前 16 位数字,然后获取从位置 2 开始的第二个 16 位数字,然后是第三位,依此类推?
任何想法、想法、建议或解决方案将不胜感激并+1。
c# ×7
sql-server ×4
asynchronous ×2
encryption ×2
async-await ×1
compression ×1
cryptography ×1
filestream ×1
quartz.net ×1
regex ×1
sql ×1
t-sql ×1