Tag: .net 4.5

静态HttpClient仍然创建TIME_WAIT tcp端口

我正在使用.NET Framework中的HttpClient(4.5.1 +,4.6.1和4.7.2)遇到一些有趣的行为。 我已经提议在工作中的一些项目中进行一些更改,以便在每次使用时不处理HttpClient,因为TCP端口使用率很高的已知问题,请参阅https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong / 。 我已经调查了这些更改,以检查事情是否按预期工作,并发现我们仍然遇到与以前相同的TIME_WAIT端口。 为了确认我提出的更改是正确的,我已经向应用程序添加了一些额外的跟踪,以确认我在整个应用程序中使用了相同的HttpClient实例。 我已经使用过简单的测试应用程序(取自上面链接的aspnetmonsters网站。 using System; using System.Net.Http; namespace ConsoleApplication { public class Program { private static HttpClientHandler { UseDefaultCredentials = true }; private static HttpClient Client = new HttpClient(handler); public static async Task Main(string[] args) { Console.WriteLine(“Starting connections”); for(int i = 0; i<10; i++) { var result = await […]

Ajax.BeginForm指定“GET”类型的发布

我的观点如下: @using (Ajax.BeginForm(new AjaxOptions { HttpMethod = “Get”, InsertionMode = InsertionMode.Replace, UpdateTargetId = “DisplayPatients” })) { } 每当我尝试编译并查看我得到的html页面的来源时,我看到, 但是,在我的Ajax.BeginForm中,我指定了HttpMethod = Get 。 尽管如此,我在输出html页面中得到了method = “post” 。 有什么想法吗? 提前致谢。 编辑: 我甚view-source在浏览器中通过view-source检查了我的页面源view-source 。 由此可见: (注意脚本(jquery-unobstrusive)实际上就在那里)

Windowsapp store中的密码哈希

我正在为我的应用程序编写身份validation服务。 客户端将通过HTTP连接到此身份validation服务以进行注册或连接。 连接后,他们将收到一个会话密钥,他们可以使用加密的TCP / UDP数据包发送到辅助服务器。 这仍然是WIP所以,只是为了给你一个大图概述。 在Serverside中,我使用BCrypt来哈希传入的密码。 并将其存储在数据库中。 在Serverside中,我还使用BCrypts Verify方法检查存储哈希的任何传入密码。 所以这基本上有效。 但是,我自然不想通过线路传输未加密的密码。 Windows Store应用程序没有BCrypt,但我发现了一些MSDN示例代码,演示了如何使用新的Cryptography API for Windows Store应用程序来散列字符串,如下所示: public static string Hash(string password) { HashAlgorithmProvider provider = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha512); CryptographicHash hash = provider.CreateHash(); IBuffer buffer = CryptographicBuffer.ConvertStringToBinary(password, BinaryStringEncoding.Utf16BE); hash.Append(buffer); IBuffer hashedBuffer = hash.GetValueAndReset(); return CryptographicBuffer.EncodeToBase64String(hashedBuffer); } 我计划让各种客户端连接到该服务,而不仅仅是Windowsapp store应用程序(也是传统的Windows桌面应用程序)。 所以很自然地我想要“一种”方式来散列密码客户端。 我需要有关我应该实现的其他安全机制的建议,如果使用SHA512对密码客户端进行散列,如上面的代码中所示,在将其传输到服务器(在存储之前再次散列并加盐)时“足够”。

Linux上的.net核心应用程序目标.net框架4.5.2

我想更多地了解点网核心支持。 我的基本理解是,如果我想在Linux上运行.net应用程序,那么需要构建.net核心和目标netcoreapp1.0框架来保证这一点。 1)我假设上述假设是正确的? 2)当我在线阅读各种文章时,例如关于在.net核心应用程序中引用退出.net框架项目的文章( https://www.hanselman.com/blog/HowToReferenceAnExistingNETFrameworkProjectInAnASPNETCore10WebApp.aspx )如果我这样做,大概是该应用程序只能在Windows而不是Linux上运行? 3)在以下文章中: https : //blogs.msdn.microsoft.com/cesardelatorre/2016/06/28/running-net-core-apps-on-multiple-frameworks-and-what-the-target-framework -monikers-tfms-are-about /在运行.net运行4.5.2选项( dotnet run -f NET452 )的dotnet run -f NET452 ,提到: 如果这个应用程序在.NET核心平台上运行,让我们说在Linux机器或Mac上,这个代码将不会被执行,但该应用程序仍将在Linux或MacOS上运行。 运行和不执行之间的区别是什么? 如果我的初步理解是正确的,那么通过在Linux上运行.net 4.5.2选项,我不希望应用程序根本不运行。 欣赏那里的几个问题,但真的想要了解更多.net核心。

等待事情发生 – 异步或同步模型?

我有这个方法WaitForReaderArrival ,如下所示:( 等待读者到达的所有时间运行) public void WaitForReaderArrival() { do { if (ReaderArrived()) { break; } System.Threading.Thread.Sleep(1000); } while (ReaderArrived() == false); } 而我正在等待读者使用, await Task.Run(new Action(WaitForReaderArrival)); if (ReaderArrived()) { //Raise an ReaderArrived here! ..//blah blah } 我的一位同事让我改变上面这句话 WaitForReaderArrival(); if (ReaderArrived()) { //Raise an ReaderArrived here! ..//blah blah } 问题是: 我上面采用的异步模型是不是真的有用? 为什么她要我将这一行更改为正常的同步方法仍然是一个问题。 以上是等待事情发生然后继续的正确方法?

带有RTZ2时区的.Net Framework问题

我们似乎在.Net Framework 4.5中发现了RTZ2时区(俄罗斯标准时间)的问题。 如果您尝试将2014-01-01 00:00:00和2014-01-01 00:59:59之间的时间(在RTZ2时区中)转换为UTC,则会出现错误: The supplied DateTime represents an invalid time. For example, when the clock is adjusted forward, any time in the period that is skipped is invalid. The supplied DateTime represents an invalid time. For example, when the clock is adjusted forward, any time in the period that is skipped is […]

如何使用CallerMemberName属性更改ILoggerFacade实现以跟踪调用方法?

我正在尝试将记录function实现到我的新WPF 4.5 CompositeWPF(Prism)项目中。 这要求我在我的代码中实现ILoggerFacade。 接口只实现1种方法: Log(string message, Category category, Priority priority) 。 ILoggerFacade接口: public interface ILoggerFacade { void Log(string message, Category category, Priority priority); } 我的实施: public class Log4NetLogger : ILoggerFacade { private static readonly ILog m_Logger = LogManager.GetLogger(typeof(ILoggerFacade)); public void Log(string message, Category category, Priority priority) { switch (category) { case Category.Debug: m_Logger.Debug(message); break; […]

如何使HttpWebRequest异步

我有这样的代码: private async Task Request(url) { Task task = null; try { task = MakeAsyncRequest(url, “text/html”); return await task; } catch { return null; } } private async Task MakeAsyncRequest(string url, string contentType) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = contentType; request.Method = WebRequestMethods.Http.Get; request.Timeout = 20000; request.Proxy = null; Task task = Task.Factory.FromAsync( request.BeginGetResponse, […]

C#异步等待澄清?

我在这里读到: 等待检查等待它是否已经完成; 如果等待已经完成,那么该方法就会继续运行(同步,就像常规方法一样)。 什么 ? 当然它还没有完成,因为它还没有开始! 例子: public async Task DoSomethingAsync() { await DoSomething(); } 在这里await检查await它是否已经完成(根据文章),但它(DoSomething)尚未开始活动! ,结果总是 false 如果文章要说: Await检查等待是否已经在x毫秒内完成; (超时) 我可能在这里错过了什么..

无法在app.config上写入设置(或者不显示任何更改)

我正在.net framework 4.5上创建一个应用程序 每当我想加载应用程序配置值(appSettings部分)并写入更改时,如果我刷新该部分,我看不到我的更改。 我做错了什么? 我该如何解决? 码 private void LoadConfig() { NameValueCollection appSettings = ConfigurationManager.AppSettings; for (int i = 0; i < appSettings.Count; i++) { switch (appSettings.GetKey(i)) { case "initialCatalog": txtInitialCatalog.Text = appSettings.GetValues(i)[0]; break; case "dataSource": txtDatasource.Text = appSettings.GetValues(i)[0]; break; case "userName": txtUsername.Text = appSettings.GetValues(i)[0]; break; case "password": txtPassword.Text = appSettings.GetValues(i)[0]; break; case "portalUrl": txtUrl.Text […]