Search Results

Search found 105 results on 5 pages for 'ihttphandler'.

Page 1/5 | 1 2 3 4 5  | Next Page >

  • Cannot resolve IHttpHandler

    - by baron
    For some reason when I am trying to create a class which implements IHttpHandler I cannot resolve IHttpHandler. Statements like: using System.Web; are not helping either. This is a class library project, I am following example here: http://www.15seconds.com/issue/020417.htm What am I doing wrong?

    Read the article

  • Issue with IHttpHandler and relative URLs

    - by vtortola
    Hi, I've developed a IHttpHandler class and I've configured it as verb="*" path="*", so I'm handling all the request with it in an attempt of create my own REST implementation for a test web site that generates the html dynamically. So, when a request for a .css file arrives, I've to do something like context.Response.WriteFile(Server.MapPath(url)) ... same for pictures and so on, I have to response everything myself. My main issue, is when I put relative URLs in the anchors; for example, I have main page with a link like this <a href="page1">Go to Page 1</a> , and in Page 1 I have another link <a href="page2">Go to Page 2</a>. Page 1 and 2 are supposed to be at the same level (http://host/page1 and http://host/page2, but when I click in Go to Page 2, I got this url in the handler: ~/page1/~/page2 ... what is a pain, because I have to do an url = url.SubString(url.LastIndexOf('~')) for clean it, although I feel that there is nothing wrong and this behavior is totally normal. Right now, I can cope with it, but I think that in the future this is gonna bring me some headache. I've tried to set all the links with absolute URLs using the information of context.Request.Url, but it's also a pain :D, so I'd like to know if there is a nicer way to do these kind of things. Don't hesitate in giving me pretty obvious responses because I'm pretty new in web development and probably I'm skipping something basic about URLs, Http and so on. Thanks in advance and kind regards.

    Read the article

  • .net IHTTPHandler Streaming SQL Binary Data

    - by Yisman
    Hello everybody I am trying to implement an ihttphandeler for streaming files. files may be tiny thumbnails or gigantic movies the binaries r stored in sql server i looked at a lot of code online but something does not make sense isnt streaming supposed to read the data piece by piece and move it over the line? most of the code seems to first read the whole field from mssql to memory and then use streaming for the output writing wouldnt it b more eficient to actually stream from disk directly to http byte by byte (or buffered chunks?) heres my code so far but cant figure out the correct combination of the sqlreader mode and the stream object and the writing system Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest context.Response.BufferOutput = False Dim FileField=safeparam(context.Request.QueryString("FileField")) Dim FileTable=safeparam(context.Request.QueryString("FileTable")) Dim KeyField=safeparam(context.Request.QueryString("KeyField")) Dim FileKey=safeparam(context.Request.QueryString("FileKey")) Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("Main").ConnectionString) Using command As New SqlCommand("SELECT " & FileField & "Bytes," & FileField & "Type FROM " & FileTable & " WHERE " & KeyField & "=" & FileKey, connection) command.CommandType = Data.CommandType.Text enbd using end using end sub please be aware that this sql command also returns the file extension (pdf,jpg,doc...) in the second field of the query thank you all very much

    Read the article

  • public class ImageHandler : IHttpHandler

    - by Ken
    cmd.Parameters.AddWithValue("@id", new system.Guid (imageid)); What using System reference would this require? Here is the handler: using System; using System.Collections.Specialized; using System.Web; using System.Web.Configuration; using System.Web.Security; using System.Globalization; using System.Configuration; using System.Data.SqlClient; using System.Data; using System.IO; using System.Web.Profile; using System.Drawing; public class ImageHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { string imageid; if (context.Request.QueryString["id"] != null) imageid = (context.Request.QueryString["id"]); else throw new ArgumentException("No parameter specified"); context.Response.ContentType = "image/jpeg"; Stream strm = ShowProfileImage(imageid.ToString()); byte[] buffer = new byte[8192]; int byteSeq = strm.Read(buffer, 0, 8192); while (byteSeq > 0) { context.Response.OutputStream.Write(buffer, 0, byteSeq); byteSeq = strm.Read(buffer, 0, 8192); } //context.Response.BinaryWrite(buffer); } public Stream ShowProfileImage(String imageid) { string conn = ConfigurationManager.ConnectionStrings["MyConnectionString1"].ConnectionString; SqlConnection connection = new SqlConnection(conn); string sql = "SELECT image FROM Profile WHERE UserId = @id"; SqlCommand cmd = new SqlCommand(sql, connection); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@id", new system.Guid (imageid));//Failing Here!!!! connection.Open(); object img = cmd.ExecuteScalar(); try { return new MemoryStream((byte[])img); } catch { return null; } finally { connection.Close(); } } public bool IsReusable { get { return false; } } }

    Read the article

  • Why is IHttpAsyncHandler being called over IHttpHandler?

    - by Tim Hardy
    I made a custom handler that derives from MvcHandler. I have my routes using a custom RouteHandler that returns my new handler for GetHttpHandler(), and I override ProcessRequest() in my custom handler. The call to GetHttpHandler is triggering a breakpoint and my handler's constructor is definitely being called, but BeginProcessRequest() is being called on the base MvcHandler instead of ProcessRequest(). Why are the async methods being called when I haven't done anything to call them? I don't want asynchronous handling, and I certainly didn't do anything explicit to get it. My controllers all derive from Controller, not AsyncController. I don't have the source code with me right now, but I can add it later if needed. I was hoping someone might know some of the reasons why BeginProcessRequest might be called when it's not wanted.

    Read the article

  • How to enable OutputCache with an IHttpHandler

    - by Joseph Kingry
    I have an IHttpHandler that I would like to hook into the OutputCache support so I can offload cached data to the IIS kernel. I know MVC must do this somehow, I found this in OutputCacheAttribute: public override void OnResultExecuting(ResultExecutingContext filterContext) { if (filterContext == null) { throw new ArgumentNullException("filterContext"); } // we need to call ProcessRequest() since there's no other way to set the Page.Response intrinsic OutputCachedPage page = new OutputCachedPage(_cacheSettings); page.ProcessRequest(HttpContext.Current); } private sealed class OutputCachedPage : Page { private OutputCacheParameters _cacheSettings; public OutputCachedPage(OutputCacheParameters cacheSettings) { // Tracing requires Page IDs to be unique. ID = Guid.NewGuid().ToString(); _cacheSettings = cacheSettings; } protected override void FrameworkInitialize() { // when you put the <%@ OutputCache %> directive on a page, the generated code calls InitOutputCache() from here base.FrameworkInitialize(); InitOutputCache(_cacheSettings); } } But not sure how to apply this to an IHttpHandler. Tried something like this, but of course this doesn't work: public class CacheTest : IHttpHandler { public void ProcessRequest(HttpContext context) { OutputCacheParameters p = new OutputCacheParameters { Duration = 3600, Enabled = true, VaryByParam = "none", Location = OutputCacheLocation.Server }; OutputCachedPage page = new OutputCachedPage(p); page.ProcessRequest(context); context.Response.ContentType = "text/plain"; context.Response.Write(DateTime.Now.ToString()); context.Response.End(); } public bool IsReusable { get { return true; } } }

    Read the article

  • Creating a System.Web.UI.Page programatically in IHTTPHandler

    - by ObiWanKenobi
    I am trying to use the ASP.NET (3.5) "Routing Module" functionality to create custom pages based on the contents of the URL. Various articles, such as this one: http://blogs.msdn.com/mikeormond/archive/2008/05/14/using-asp-net-routing-independent-of-mvc.aspx explain how to use ASP.NET Routing to branch to existing pages on the web server. What I would like to do is create the page on-the-fly using code. My first attempt looks like this: public class SimpleRouteHandler : IRouteHandler { public IHttpHandler GetHttpHandler(RequestContext requestContext) { string pageName = requestContext.RouteData.GetRequiredString("PageName"); Page myPage = new Page(); myPage.Response.Write("hello " + pageName); return myPage; } } But this throws an HTTPException saying "Response is not available in this context." at the Response.Write statement. Any ideas on how to proceed? UPDATE: In the end, I went with an approach based on IHttpModule, which turned out to be rather easy.

    Read the article

  • Can't get jQuery AutoComplete to work with External JSON

    - by rockinthesixstring
    I'm working on an ASP.NET app where I'm in need of jQuery AutoComplete. Currently there is nothing happening when I type data into the txt63 input box (and before you flame me for using a name like txt63, I know, I know... but it's not my call :D ). Here's my javascript code <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js" type="text/javascript"></script> <script src="http://jquery-ui.googlecode.com/svn/tags/latest/external/jquery.bgiframe-2.1.1.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/i18n/jquery-ui-i18n.min.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> var theSource = '../RegionsAutoComplete.axd?PID=<%= hidden62.value %>' $(function () { $('#<%= txt63.ClientID %>').autocomplete({ source: theSource, minLength: 2, select: function (event, ui) { $('#<%= hidden63.ClientID %>').val(ui.item.id); } }); }); and here is my HTTP Handler Namespace BT.Handlers Public Class RegionsAutoComplete : Implements IHttpHandler Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable Get Return False End Get End Property Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest 'the page contenttype is plain text context.Response.ContentType = "application/json" context.Response.ContentEncoding = Encoding.UTF8 'set page caching context.Response.Cache.SetExpires(DateTime.Now.AddHours(24)) context.Response.Cache.SetCacheability(HttpCacheability.Public) context.Response.Cache.SetSlidingExpiration(True) context.Response.Cache.VaryByParams("PID") = True Try ' use the RegionsDataContext Using RegionDC As New DAL.RegionsDataContext ' query the database based on the querysting PID Dim q = (From r In RegionDC.bt_Regions _ Where r.PID = context.Request.QueryString("PID") _ Select r.Region, r.ID) ' now we loop through the array ' and write out the ressults Dim sb As New StringBuilder sb.Append("{") For Each item In q sb.Append("""" & item.Region & """: """ & item.ID & """,") Next sb.Append("}") context.Response.Write(sb.ToString) End Using Catch ex As Exception HealthMonitor.Log(ex, False, "This error occurred while populating the autocomplete handler") End Try End Sub End Class End Namespace The rest of my ASPX page has the appropriate controls as I had this working with the old version of the jQuery library. I'm trying to get it working with the new one because I heard that the "dev" CDN was going to be obsolete. Any help or direction will be greatly appreciated.

    Read the article

  • custom httphandler in asp.net cannot get request querystring?

    - by Sander
    i've been trying to get this to work. its basicly a way to have certain MVC pages work within a webforms cms (umbraco) someone tried it before me and had issues with MVC2.0 (see here), i read the post, did what was announced there, but with or without that code, i seem to get stuck on a different matter. it seems like, if i call an url, it fires the handler, but fails to request the querystring passed, the variable originalPath is always empty, for example i call this url: http://localhost:8080/mvc.ashx?mvcRoute=/home/RSVPForm the handler is supposed to get the mvcRoute but it is always empty. thus gets rewritten to a simple / and then returns resource cannot be found error. here is the code i use now public void ProcessRequest(HttpContext httpContext) { string originalPath = httpContext.Request.Path; string newPath = httpContext.Request.QueryString["mvcRoute"]; if (string.IsNullOrEmpty(newPath)) newPath = "/"; HttpContext.Current.RewritePath(newPath, false); IHttpHandler ih = (IHttpHandler)new MvcHttpHandler(); ih.ProcessRequest(httpContext); HttpContext.Current.RewritePath(originalPath, false); } i would like some new input on this as i'm staring myself blind on such a simple issue, while i thought i would have more problems with mvc itself :p Edit have no time to investigate, but after copying the site over to different locations, using numerous web.config changes (unrelated to this error but was figuring other things out) this error seems to have solved itself. so its no longer an issue, however i have no clue as to what exactly made this to work again.

    Read the article

  • ASP.NET - Dynamically register an HttpHandler in code (not in web.config)

    - by Sunday Ironfoot
    Is there a way I can dynamically register an IHttpHandler in C# code, instead of having to manually add it to the system.web/httpHandlers section in the web.config. This may sound crazy, but I have good reason for doing this. I'm building a WidgetLibrary that a website owner can use just by dropping a .dll file into their bin directory, and want to support this with minimal configuration to the web.config.

    Read the article

  • Does ASP.net 1.1 support Generic HttpHandlers ?

    - by Campos
    I need to get an image from a SQL Server as a byte[], and load it to a WebControl.Image. The only seemingly good way to do it that I found is to implement IHttpHandler and handle the request accordingly. But I'm stuck to using asp.net 1.1. Does it support ashx files?

    Read the article

  • Why does IHttpAsyncHandler leak memory under load?

    - by Anton
    I have noticed that the .NET IHttpAsyncHandler (and the IHttpHandler, to a lesser degree) leak memory when subjected to concurrent web requests. In my tests, the development web server (Cassini) jumps from 6MB memory to over 100MB, and once the test is finished, none of it is reclaimed. The problem can be reproduced easily. Create a new solution (LeakyHandler) with two projects: An ASP.NET web application (LeakyHandler.WebApp) A Console application (LeakyHandler.ConsoleApp) In LeakyHandler.WebApp: Create a class called TestHandler that implements IHttpAsyncHandler. In the request processing, do a brief Sleep and end the response. Add the HTTP handler to Web.config as test.ashx. In LeakyHandler.ConsoleApp: Generate a large number of HttpWebRequests to test.ashx and execute them asynchronously. As the number of HttpWebRequests (sampleSize) is increased, the memory leak is made more and more apparent. LeakyHandler.WebApp TestHandler.cs namespace LeakyHandler.WebApp { public class TestHandler : IHttpAsyncHandler { #region IHttpAsyncHandler Members private ProcessRequestDelegate Delegate { get; set; } public delegate void ProcessRequestDelegate(HttpContext context); public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData) { Delegate = ProcessRequest; return Delegate.BeginInvoke(context, cb, extraData); } public void EndProcessRequest(IAsyncResult result) { Delegate.EndInvoke(result); } #endregion #region IHttpHandler Members public bool IsReusable { get { return true; } } public void ProcessRequest(HttpContext context) { Thread.Sleep(10); context.Response.End(); } #endregion } } LeakyHandler.WebApp Web.config <?xml version="1.0"?> <configuration> <system.web> <compilation debug="false" /> <httpHandlers> <add verb="POST" path="test.ashx" type="LeakyHandler.WebApp.TestHandler" /> </httpHandlers> </system.web> </configuration> LeakyHandler.ConsoleApp Program.cs namespace LeakyHandler.ConsoleApp { class Program { private static int sampleSize = 10000; private static int startedCount = 0; private static int completedCount = 0; static void Main(string[] args) { Console.WriteLine("Press any key to start."); Console.ReadKey(); string url = "http://localhost:3000/test.ashx"; for (int i = 0; i < sampleSize; i++) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.BeginGetResponse(GetResponseCallback, request); Console.WriteLine("S: " + Interlocked.Increment(ref startedCount)); } Console.ReadKey(); } static void GetResponseCallback(IAsyncResult result) { HttpWebRequest request = (HttpWebRequest)result.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result); try { using (Stream stream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(stream)) { streamReader.ReadToEnd(); System.Console.WriteLine("C: " + Interlocked.Increment(ref completedCount)); } } response.Close(); } catch (Exception ex) { System.Console.WriteLine("Error processing response: " + ex.Message); } } } }

    Read the article

  • Webclient using download file to grab file from server - handling exceptions

    - by baron
    Hello everyone, I have a web service in which I am manipulating POST and GET methods to facilitate upload / download functionality for some files in a client/server style architecture. Basically the user is able to click a button to download a specific file, make some changes in the app, then click upload button to send it back. Problem I am having is with the download. Say the user expects 3 files 1.txt, 2.txt and 3.txt. Except 2.txt does not exist on the server. So I have code like (on server side): public class HttpHandler : IHttpHandler { public void ProcessRequest { if (context.Request.HttpMethod == "GET") { GoGetIt(context) } } private static void GoGetIt(HttpContext context) { var fileInfoOfWhereTheFileShouldBe = new FileInfo(......); if (!fileInfoOfWhereTheFileShouldBe.RefreshExists()) { throw new Exception("Oh dear the file doesn't exist"); } ... So the problem I have is that when I run the application, and I use a WebClient on client side to use DownloadFile method which then uses the code I have above, I get: WebException was unhandled: The remote server returned an error: (500) Internal Server Error. (While debugging) If I attach to the browser and use http://localhost:xxx/1.txt I can step through server side code and throw the exception as intended. So I guess I'm wondering how I can handle the internal server error on the client side properly so I can return something meaningful like "File doesn't exist". One thought was to use a try catch around the WebClient.DownloadFile(address, filename) method but i'm not sure thats the only error that will occur i.e. the file doesn't exist.

    Read the article

  • Web.Routing for the site root or homepage

    - by Aquinas
    I am doing some work with Web.Routing, using it to have friendly urls and nice Rest like interfaces to a site that is essentially rendered by a single IHttpHandler. There are no webforms, the handler generates all the html/json and writes it as part of process request. This works well for things like /Sites/Accounting for example, but I can't get it to work for the site root, i.e. '/'. I have tried registering a route with an empty string, with 'default.aspx' (which is the empty aspx file I keep in my root folder to play nice with cassini and iis). I set RouteExistingFiles to false explicitly, but whatever I do when hitting the root url it still opens default.axpx, which has no code it inherits from, and contains a simple h1 tag to show that I've hit it. I don't want to change the default file to redirect to a desired route, I just want the equivalent of a 'default' route that is applied when no other routes are found, similar to MVC. For reference, the previous version of the site didn't use Web.Routing, but had a handler referenced in the web.config that was perfectly capable of intercepting requests for the root or default.aspx. Specs: ASP.NET 3.5sp1, C#, no webforms, MVC or openrasta. Plain old IHttpHandlers.

    Read the article

  • File transfer eating alot of CPU

    - by Dan C.
    I'm trying to transfer a file over a IHttpHandler, the code is pretty simple. However when i start a single transfer it uses about 20% of the CPU. If i were to scale this to 20 simultaneous transfers the CPU is very high. Is there a better way I can be doing this to keep the CPU lower? the client code just sends over chunks of the file 64KB at a time. public void ProcessRequest(HttpContext context) { if (context.Request.Params["secretKey"] == null) { } else { accessCode = context.Request.Params["secretKey"].ToString(); } if (accessCode == "test") { string fileName = context.Request.Params["fileName"].ToString(); byte[] buffer = Convert.FromBase64String(context.Request.Form["data"]); string fileGuid = context.Request.Params["smGuid"].ToString(); string user = context.Request.Params["user"].ToString(); SaveFile(fileName, buffer, user); } } public void SaveFile(string fileName, byte[] buffer, string user) { string DirPath = @"E:\Filestorage\" + user + @"\"; if (!Directory.Exists(DirPath)) { Directory.CreateDirectory(DirPath); } string FilePath = @"E:\Filestorage\" + user + @"\" + fileName; FileStream writer = new FileStream(FilePath, File.Exists(FilePath) ? FileMode.Append : FileMode.Create, FileAccess.Write, FileShare.ReadWrite); writer.Write(buffer, 0, buffer.Length); writer.Close(); }

    Read the article

  • XML Parseing Error when serving a PDF

    - by Andy
    I'm trying to serve a pdf file from a database in ASP.NET using an Http Handler, but every time I go to the page I get an error XML Parsing Error: no element found Location: https://ucc489/rc/NoteFileHandler.ashx?noteId=1,msdsId=3 Line Number 1, Column 1: ^ Here is my HttpHandler code: public class NoteFileHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { if (context.Request.QueryString.HasKeys()) { if (context.Request.QueryString["noteId"] != null && context.Request.QueryString["msdsId"] != null) { string nId = context.Request.QueryString["noteId"]; string mId = context.Request.QueryString["msdsId"]; DataTable noteFileDt = App_Models.Notes.GetNoteFile(nId, mId); if (noteFileDt.Rows.Count > 0) { try { context.Response.Clear(); context.Response.AddHeader("content-disposition", "attachment;filename=" + noteFileDt.Rows[0][0] + ".pdf"); context.Response.ContentType = "application/pdf"; byte[] file = (byte[])noteFileDt.Rows[0][1]; context.Response.BinaryWrite(file); context.Response.End(); } catch { context.Response.ContentType = "text/plain"; context.Response.Write("File Not Found"); context.Response.StatusCode = 404; } } } } } public bool IsReusable { get { return false; } } } Is there anything else I need to do (server configuration/whatever) to get my pdf file to load?

    Read the article

  • Why is this class library dll not getting information from app.config

    - by baron
    I am developing a custom HttpHandler, to do so I write a C# Class Library and compile to DLL. As part of this I have some directory locations which I want not hard coded in the app, so i'm trying to put it in the app.config which I've used before. Before this has worked by just going building the app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="Share" value="C:\...\"/> </appSettings> </configuration> And then obtaining this in code like: var shareDirectory = ConfigurationManager.AppSettings["Share"]; But when I compile it and put it in the bin folder for the webservice, it keeps getting null for shareDirectory, probably because it can't find app.config. So how do I make sure this is included so I don't have to hard code my direcotry locations? I notice it will essentially after compiled we get the assembly.dll and the assembly.dll.config which is the app.config file, so it's definetly there in the bin folder!

    Read the article

  • HttpHandler instance and HttpApplication object - does the latter...?

    - by SourceC
    A Book showed an example where ( when using IIS7 ) the following module was configured such that it would be used by any web application ( even by non-asp.net apps ) running on a web site. But: A) if this module is invoked for non-asp.net application, then how or why would HttpApplication object still be created, since non-asp.net apps don’t run in the context of CLR ( and thus Asp.Net runtime also won’t run )? b) Assuming HttpApplication object is also created for non-asp.net apps, why then does the code inside Init() event handler have to check for whether HttpApplication object actually exists? Why wouldn’t it exist? Isn’t this HttpApplication object which actually instantiates Http module instance? Here is Http handler: public class SimpleSqlLogging : IHttpModule { private HttpApplication _CurrentApplication; public void Dispose() { _CurrentApplication = null; } public void Init(HttpApplication context) { // Attach to the incoming request event _CurrentApplication = context; if (context != null) { context.BeginRequest += new EventHandler(context_BeginRequest); } } void context_BeginRequest(object sender, EventArgs e) { ... } }

    Read the article

  • Session variable getting lost using Firefox, works in IE

    - by user328422
    I am setting a Session variable in an HttpHandler, and then getting its value in the Page_load event of an ASPX page. I'm setting it using public void ProcessRequest(HttpContext context) { HttpPostedFile file = context.Request.Files["Filedata"]; context.Session["WorkingImage"] = file.FileName; } (And before someone suggests that I check the validity of file.FileName, this same problem occurs if I hard-code a test string in there.) It's working just fine in IE, but in Firefox the Session Variable is not found, getting the "Object reference not set to an instance of an object" error in the following code: protected void Page_Load(object sender, EventArgs e) { string loc = Session["WorkingImage"].ToString(); } Has anyone encountered this problem - and hopefully come up with a means for passing the session variable?

    Read the article

  • Global Handler in IIS7 (Classic Mode) gives "Failed to Execute" error

    - by Akash Kava
    I have made a custom handler called MyIndexHandler and I want it to handle *.index requests, now as I want this handler to be executed by any website, I installed my handler with following two steps in IIS manager. Add MyIndexHandler.dll in GAC Add Managed Module for *.index, the drop down in IIS displays my index handler correctly so it means it did find it correctly from the GAC. I added Script map for aspnet_isapi.dll for *.index (this is required for classic mode) Now in any of my website if I try xyz.index, my handler does not get called and it returns "Failed to execute URL", now this only happens when IIS is unable to find the mapped handler, but I already have defined mapped handler at IIS level and when i try to add entry in web.config manually for this handler, it tells me you can not define multiple handler, it means that IIS finds my handler, mapping but for some reason it does not execute it.

    Read the article

  • C# Image HttpHandler: Disable cookies in handler (YSlow / Google PageSpeed)

    - by user319111
    Hi. I have a HttpHandler for resizing images, round corners, reflection etc etc. This i working OK. The problem i have is, that some data is stored in cookies, and the cookies are send to images, when they are shown. Is there any way to disable this globally (cookie-free requests) in web.config, or even in the HttpHandler itself? Example page: http://test.roob.dk/dk/product/ray-ban-rb3359-polarized-16/ Thanks in advance CP // Denmark

    Read the article

  • Am I using handlers in the wrong way?

    - by superexsl
    Hey, I've never used HTTP Handlers before, and I've got one working, but I'm not sure if I'm actually using it properly. I have generated a string which will be saved as a CSV file. When the user clicks a button, I want the download dialog box to open so that the user can save the file. What I have works, but I keep reading about modifying the web.config file and I haven't had to do that. My Handler: private string _data; private string _title = "temp"; public void AddData(string data) { _data = data; } public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/csv"; context.Response.AddHeader("content-disposition", "filename=" + _title + ".csv"); context.Response.Write(_data); context.Response.Flush(); context.Response.Close(); } And this is from the page that allows the user to download: (on button click) string dataToConvert = "MYCSVDATA...."; csvHandler handler = new csvHandler(); handler.AddData(dataToConvert); handler.ProcessRequest(this.Context); This works fine, but no examples I've seen ever instantiate the handler and always seem to modify the web.config. Am I doing something wrong? Thanks

    Read the article

  • ASP.NET Web Forms Extensibility: Handler Factories

    - by Ricardo Peres
    An handler factory is the class that implements IHttpHandlerFactory and is responsible for instantiating an handler (IHttpHandler) that will process the current request. This is true for all kinds of web requests, whether they are for ASPX pages, ASMX/SVC web services, ASHX/AXD handlers, or any other kind of file. Also used for restricting access for certain file types, such as Config, Csproj, etc. Handler factories are registered on the global Web.config file, normally located at %WINDIR%\Microsoft.NET\Framework<x64>\vXXXX\Config for a given path and request type (GET, POST, HEAD, etc). This goes on section <httpHandlers>. You would create a custom handler factory for a number of reasons, let me list just two: A centralized place for using dependency injection; Also a centralized place for invoking custom methods or performing some kind of validation on all pages. Let’s see an example using Unity for injecting dependencies into a page, suppose we have this on Global.asax.cs: 1: public class Global : HttpApplication 2: { 3: internal static readonly IUnityContainer Unity = new UnityContainer(); 4: 5: void Application_Start(Object sender, EventArgs e) 6: { 7: Unity.RegisterType<IFunctionality, ConcreteFunctionality>(); 8: } 9: } We instantiate Unity and register a concrete implementation for an interface, this could/should probably go in the Web.config file. Forget about its actual definition, it’s not important. Then, we create a custom handler factory: 1: public class UnityPageHandlerFactory : PageHandlerFactory 2: { 3: public override IHttpHandler GetHandler(HttpContext context, String requestType, String virtualPath, String path) 4: { 5: IHttpHandler handler = base.GetHandler(context, requestType, virtualPath, path); 6: 7: //one scenario: inject dependencies 8: Global.Unity.BuildUp(handler.GetType(), handler, String.Empty); 9:  10: return (handler); 11: } 12: } It inherits from PageHandlerFactory, which is .NET’s included factory for building regular ASPX pages. We override the GetHandler method and issue a call to the BuildUp method, which will inject required dependencies, if any exist. An example page with dependencies might be: 1: public class SomePage : Page 2: { 3: [Dependency] 4: public IFunctionality Functionality 5: { 6: get; 7: set; 8: } 9: } Notice the DependencyAttribute, it is used by Unity to identify properties that require dependency injection. When BuildUp is called, the Functionality property (or any other properties with the DependencyAttribute attribute) will receive the concrete implementation associated with it’s type, as registered on Unity. Another example, checking a page for authorization. Let’s define an interface first: 1: public interface IRestricted 2: { 3: Boolean Check(HttpContext ctx); 4: } An a page implementing that interface: 1: public class RestrictedPage : Page, IRestricted 2: { 3: public Boolean Check(HttpContext ctx) 4: { 5: //check the context and return a value 6: return ...; 7: } 8: } For this, we would use an handler factory such as this: 1: public class RestrictedPageHandlerFactory : PageHandlerFactory 2: { 3: private static readonly IHttpHandler forbidden = new UnauthorizedHandler(); 4:  5: public override IHttpHandler GetHandler(HttpContext context, String requestType, String virtualPath, String path) 6: { 7: IHttpHandler handler = base.GetHandler(context, requestType, virtualPath, path); 8: 9: if (handler is IRestricted) 10: { 11: if ((handler as IRestricted).Check(context) == false) 12: { 13: return (forbidden); 14: } 15: } 16:  17: return (handler); 18: } 19: } 20:  21: public class UnauthorizedHandler : IHttpHandler 22: { 23: #region IHttpHandler Members 24:  25: public Boolean IsReusable 26: { 27: get { return (true); } 28: } 29:  30: public void ProcessRequest(HttpContext context) 31: { 32: context.Response.StatusCode = (Int32) HttpStatusCode.Unauthorized; 33: context.Response.ContentType = "text/plain"; 34: context.Response.Write(context.Response.Status); 35: context.Response.Flush(); 36: context.Response.Close(); 37: context.ApplicationInstance.CompleteRequest(); 38: } 39:  40: #endregion 41: } The UnauthorizedHandler is an example of an IHttpHandler that merely returns an error code to the client, but does not cause redirection to the login page, it is included merely as an example. One thing we must keep in mind is, there can be only one handler factory registered for a given path/request type (verb) tuple. A typical registration would be: 1: <httpHandlers> 2: <remove path="*.aspx" verb="*"/> 3: <add path="*.aspx" verb="*" type="MyNamespace.MyHandlerFactory, MyAssembly"/> 4: </httpHandlers> First we remove the previous registration for ASPX files, and then we register our own. And that’s it. A very useful mechanism which I use lots of times.

    Read the article

  • How to save data between calls to a IHttpHandler?

    - by bartek
    I have a IHttpHandler that acts as a source to a jQuery Autocomplete input field. In the constructor of the handler I generate an index that remains fairly static between request (needs to be rebuilt maybe once a day). How can I cache the the index between calls? Debugging indicates that the constructor is called for each request. I've set IsReusable to "false".

    Read the article

1 2 3 4 5  | Next Page >