Tag: handler

System.NullReferenceException检查是否!= null

我正在使用ASHX处理程序,我希望处理程序检查Session!= null。 if (context.Session[“Username”] != null) 我得到这个错误指向这一行: System.NullReferenceException:未将对象引用设置为对象的实例。 有什么问题?

用于多媒体内容的处理程序(MIME)不起作用

我正在使用一个在页面中呈现多媒体内容的处理程序。 这个想法是这个处理程序访问文件并使用扩展来确定类型,并且呈现它, 问题在于处理程序本身被下载并且多媒体没有被呈现的大多数时候。 这是代码: FileInfo file = new FileInfo(filePath); byte[] bytes = new byte[file.Length]; using (FileStream fs = file.OpenRead()) { fs.Read(bytes, 0, bytes.Length); } string extension = Path.GetExtension(filePath); string mimeDeclaration; if (“.tif” == extension) mimeDeclaration = “tiff”; string[] imagenes = new string[] {“.jpg”, “.jpeg”, “.bmp”, “.gif”, “.png”}; if (imagenes.Any(x => x.Contains(extension))) mimeDeclaration = extension.Substring(1); else […]

我无法理解如何使用SendMessage或PostMessage调用

我需要在第三方应用程序中模拟按键。 假设我有一个需要向Calculator应用程序发送“8”的C#应用​​程序。 我不能使用.Net的SendKeys或win32 api的keybd_event,因为它们都要求窗口是最活跃的窗口,这在我的情况下不是这种情况。 这样我就可以调用sendMessage和postMessage。 我在过去的三个小时里一直试图获得一些结果,但现在我完全没有希望了。 我有以下内容: [DllImport(“user32.dll”)] public static extern int FindWindow(string lpClassName,string lpWindowName); [DllImport(“user32.dll”)] public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam); [return: MarshalAs(UnmanagedType.Bool)] [DllImport(“user32.dll”, SetLastError = true)] public static extern bool PostMessage(int hWnd, uint Msg, int wParam, int lParam); private void button1_Click(object sender, EventArgs e) { const int […]

Web API – 405 – 请求的资源不支持http方法’PUT’

我有一个Web API项目,我无法启用针对它的“PUT / Patch”请求。 我从小提琴手那里得到的回应是: HTTP/1.1 405 Method Not Allowed Cache-Control: no-cache Pragma: no-cache Allow: GET,POST,DELETE Content-Type: application/json; charset=utf-8 Expires: -1 Server: Microsoft-IIS/8.0 X-AspNet-Version: 4.0.30319 X-SourceFiles: =?UTF-8?B?QzpcUHJvamVjdHNcZG90TmV0XFdlYkFQSVxBZFNlcnZpY2VcQWRTZXJ2aWNlXGFwaVxpbXByZXNzaW9uXDE1?= X-Powered-By: ASP.NET Date: Tue, 06 May 2014 14:10:35 GMT Content-Length: 72 {“message”:”The requested resource does not support http method ‘PUT’.”} 根据上述回复,不接受“PUT”动词。 但是,我无法弄清楚相关处理程序的配置位置。 类的“Put”方法声明如下: [HttpPatch] [HttpPut] public HttpResponseMessage Put(Int32 […]