ihttphandler

Change ASP.NET MVC Routes dynamically

我的梦境 提交于 2019-12-02 22:20:28
usually, when I look at a ASP.Net MVC application, the Route table gets configured at startup and is not touched ever after. I have a couple of questions on that but they are closely related to each other: Is it possible to change the route table at runtime? How would/should I avoid threading issues? Is there maybe a better way to provide a dynamic URL? I know that IDs etc. can appear in the URL but can't see how this could be applicable in what I want to achieve. How can I avoid that, even though I have the default controller/action route defined, that default route doesn't work for a

Significance of bool IsReusable in http handler interface

我的未来我决定 提交于 2019-12-02 14:13:11
When writing a http handler/module, there is an interface member to implement called - bool IsReusable . What is the significance of this member? If I set it to false (or true), what does this mean for the rest of the web app? AnthonyWJones The normal entry point for a handler is the ProcessRequest method. However you may have code in the class constructor which puts together some instance values which are expensive to build. If you specify Reusable to be true the application can cache the instance and reuse it in another request by simply calling its ProcessRequest method again and again,

Sending XML data via HTTP POST to IHttpHandler causes HttpRequestValidationException

徘徊边缘 提交于 2019-12-01 23:35:08
I'm writing an IHttpHandler implementation that will receive XML data sent through a regular HTTP POST from another website. Here's a prototype of the implementation: public class MyHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { string s = context.Request.Form["input"]; // <== this throws HttpRequestValidationException XmlDocument doc = new XmlDocument(); doc.LoadXml(s); // ... } public bool IsReusable { get { return false; } } } I'm testing the implementation with this simple page: <body> <form method="post" action="MPSConnector.Results.dsvc"> <textarea name="input

IHttpHandler Example required for Image Type Files C# ASP.Net

妖精的绣舞 提交于 2019-12-01 10:52:38
问题 Can anyone provide a good example of IHttpHnalder for handling Image Type. I want to resize the image that's hosted on my server 回答1: Problem using iHttpHandler and How to know which image has been requested Both have examples of HTTPHandlers for serving images. 回答2: The answers by Zhaph and Ady seem to point in the right direction already, but if you need an additional example... My article on BlobStreams for the Microsoft.NET Magazine here in Holland includes a very simple example of

Image from HttpHandler won't cache in browser

牧云@^-^@ 提交于 2019-11-29 19:59:30
I'm serving up an image from a database using an IHttpHandler. The relevant code is here: public void ProcessRequest(HttpContext context) { context.Response.ContentType = "image/jpeg"; int imageID; if (int.TryParse(context.Request.QueryString["id"], out imageID)) { var photo = new CoasterPhoto(imageID); if (photo.CoasterPhotoID == 0) context.Response.StatusCode = 404; else { byte[] imageData = GetImageData(photo); context.Response.OutputStream.Write(imageData, 0, imageData.Length); context.Response.Cache.SetCacheability(HttpCacheability.Public); context.Response.Cache.SetExpires(DateTime.Now

Log file is not being written to from an HttpHandler

微笑、不失礼 提交于 2019-11-29 15:25:20
I want to capture all the requests going to *.jpg files on my server. To do so, I have created an HttpHandler whose code is as follows: using System; using System.Collections.Generic; using System.Text; using System.Web; using System.IO; using System.Globalization; namespace MyHandler { public class NewHandler : IHttpHandler { public NewHandler() {} public void ProcessRequest(System.Web.HttpContext ctx) { HttpRequest req = ctx.Request; string path = req.PhysicalPath; string extension = null; string contentType = null; extension = Path.GetExtension(path).ToLower(); switch (extension) { case "

Uploadify ashx file Context.Session gets null

徘徊边缘 提交于 2019-11-28 19:57:19
I have a file upload in my site which is done using uploadify it uses a ashx page to upload file to database.It works fine in IE but in Mozilla the context.Session is getting null.I have also used IReadOnlySessionState to read session. how can i get session in Mozilla like IE. here is the ashx code i have done public class Upload : IHttpHandler, IReadOnlySessionState { HttpContext context; public void ProcessRequest(HttpContext context) { string UserID = context.Request["UserID"]; context.Response.ContentType = "text/plain"; context.Response.Expires = -1; XmlDocument xDoc = new XmlDocument();

Image from HttpHandler won't cache in browser

让人想犯罪 __ 提交于 2019-11-28 15:13:42
问题 I'm serving up an image from a database using an IHttpHandler. The relevant code is here: public void ProcessRequest(HttpContext context) { context.Response.ContentType = "image/jpeg"; int imageID; if (int.TryParse(context.Request.QueryString["id"], out imageID)) { var photo = new CoasterPhoto(imageID); if (photo.CoasterPhotoID == 0) context.Response.StatusCode = 404; else { byte[] imageData = GetImageData(photo); context.Response.OutputStream.Write(imageData, 0, imageData.Length); context

IIS 7, HttpHandler and HTTP Error 500.21

匆匆过客 提交于 2019-11-28 09:06:21
On IIS 7, I'm trying to use custom HttpHandler for my ASP.NET web application. I use pipeline mode "classic", .NET version is 4.0.30319, my web.config configuration for the handler is: <system.webServer> <handlers> <add name="MyHandler" path="*.myExtension" verb="*" type="Company.App.UI.Controls.MyHandler, Company.App.UI" resourceType="Unspecified" /> </handlers> </system.webServer> When I invoke this handler, I get this error: HTTP Error 500.21 - Internal Server Error Handler "MyHandler" has a bad module "ManagedPipelineHandler" in its module list I did a google search, the most of people fix

Log file is not being written to from an HttpHandler

旧时模样 提交于 2019-11-28 08:46:01
问题 I want to capture all the requests going to *.jpg files on my server. To do so, I have created an HttpHandler whose code is as follows: using System; using System.Collections.Generic; using System.Text; using System.Web; using System.IO; using System.Globalization; namespace MyHandler { public class NewHandler : IHttpHandler { public NewHandler() {} public void ProcessRequest(System.Web.HttpContext ctx) { HttpRequest req = ctx.Request; string path = req.PhysicalPath; string extension = null;