C#.NET使用HttpWebRequest将文件上载到Web表单

有没有人在C#中使用HttpWebRequest将文件从本地驱动器提交到multipart / form-data Web表单?

如何调整不同分辨率的图像大小

我必须在照片库@ width = 200 height = 180中显示图像,但在上传图像时我必须调整它的大小,但问题是每个图像都有不同的分辨率。 如何以不同的分辨率调整图像大小以使图像保持完整。 这是我的代码: private void ResizeImage() { System.Drawing.Image ImageToUpload = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream); byte[] image = null; int h = ImageToUpload.Height; int w = ImageToUpload.Width; int r = int.Parse(ImageToUpload.VerticalResolution.ToString()); int NewWidth = 200;//constant int NewHeight = 180;//constant byte[] imagesize = FileUpload1.FileBytes; System.Drawing.Bitmap BitMapImage = new System.Drawing.Bitmap(ImageToUpload, NewWidth, NewHeight);//this line gives horrible […]

C#windows 10 app中的ssh连接

我一直在寻找能够帮助我解决这个问题的2天。 我需要一种从Windows 10 Universal应用程序连接到ssh服务器的方法。 这意味着普通的ssh库不起作用,并且tcpclient不存在。 我怎样才能做到这一点? 提前致谢。

如何从HttpRequestException获取JSON错误消息

我有一种情况,我必须在一个catch语句中提取一个Response( HttpResponseMessage ),但我认为无法完成(在catch中使用await )。 此外,如果我在catch之后执行此操作,则HttpResponseMessage消息将获得“Disposed”。 码: private async void MakeHttpClientPostRequest() { HttpResponseMessage response = null; try { HttpClient httpClient = new HttpClient(); httpClient.Timeout = TimeSpan.FromSeconds(15); HttpContent httpContent = null; if (postJSON != null) { httpContent = new StringContent(postJSON); httpContent.Headers.ContentType = new MediaTypeHeaderValue(“application/json”); } response = await httpClient.PostAsync(url, httpContent); if (response != null) { response.EnsureSuccessStatusCode(); netResults […]

是否可以在C#中调用静态函数内的非静态函数?

是否可以在C#中调用静态函数内使用公共非静态类的非静态函数? public class MyProgram { private Thread thd = new Thread(myStaticFunction); public AnotherClass myAnotherClass = new AnotherClass(); public MyProgram() { thd.Start(); } public static void myStaticFunction() { myNonStaticFunction(); } private void myNonStaticFunction() { myAnotherClass.DoSomethingGood(); } } 好吧,上面的无效代码就是我需要的。 任何的想法?

活动目录 – 用户的角色

我了解如何使用User.Identity和User.IsInRole 有没有办法查看用户所在的所有角色? 我们有很多小组,有些人在很多小组,但我不想写User.IsInRole 20多次。

ReadProcessMemory和WriteProcessMemory错了

我正在创建这个内存编辑器,但子程序ReadProcessMemory失败; WriteProcessMemory也是如此。 我试图通过使用GetLastError子例程获取最后一个错误,但它返回0,即ERROR_SUCCESS。 这是程序和类的代码。 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Memedit; using System.Runtime.InteropServices; namespace Memory_Editor { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void textBox1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop, false)) { e.Effect = DragDropEffects.All; } } […]

使用浏览器后退按钮注销问题

我使用ASP.Net MVC 4创建了登录/注销function。我使用自己创建的表单来针对Active Directory对用户进行身份validation。 它的function很好。 安全问题仍然存在很大问题。 用户单击注销链接后,他/她已成功注销并重新定向到登录表单。 控制器中的代码如下所示。 public ActionResult Logout() { // Tried to include below 3 lines in _Layout.cshtml as well. But not identifying. Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache); Response.Cache.SetNoStore(); Session.Abandon(); return RedirectToAction(“Login”); } 但是,一旦点击浏览器后退按钮,用户就可以返回到其他页面并浏览页面。 我通过几种解决方案,不同的方法,但没有解决。 似乎MVC方法与ASP.NET表单有很大不同。 感谢你对此的帮助。 (我希望使用C#/ MVC方式解决这个问题。在注销时不使用JavaScript来禁用/关闭浏览器。) 更新:代码片段 [HttpPost] public ActionResult Login(LoginModel authUser) { // Call Helper to get LDAP info. Will return […]

Kinect在C#WPF中录制video

我想记录我的kinect摄像头视觉。我已经搜索过,但我找不到任何C#相同的核心代码。 你有相同的简单代码或相同的建议吗? 谢谢。

Inno Setup – 具有依赖项的外部.NET DLL

我想在安装过程中在Inno Setup脚本中使用自定义DLL。 我写了一个非常简单的函数,它基本上使用MySQL .NET连接器检查MySQL数据库的连接字符串(目标服务器上没有MySQL客户端)。 这个导出函数的代码是: public class DbChecker { [DllExport(“CheckConnexion”, CallingConvention.StdCall)] public static int CheckConnexion([MarshalAs(UnmanagedType.LPStr)] string connexionString) { int success; try { MySqlConnection connection = new MySqlConnection(connexionString); connection.Open(); connection.Close(); success = 0; } catch (Exception) { success = 1; } return success; } } 该function在Inno Setup中以这种方式导入: [Files] Source: “..\..\MyDll\bin\x86\Release\*”; Flags: dontcopy; 和 [Code] function CheckConnexion(connexionString: […]