Click here to Skip to main content
12,892,796 members (60,541 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hi, I am trying to upload an image to a website, but I am not successful. I want to read the path of the picture in handler method from somewhere... I used Session, but in the handler the Session is null, even when I write something to the Session in a Page_Load of a page where is a button, which starts the handler or when I write it to the button_click method it still null.
I want to know, how can I give the Path of the image to the handler and how the code will looks like.

I have something like this, but it's unuseable and when I write some path of an existing image to parameters of the Write Method it downloads the handler, but I don't want it. I want to upload an image, which I choose to the website, does anyone know how? Thanks for replies!

public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "image/jpeg";
        string savedFileName = "";
        foreach (string file in context.Request.Files)
            HttpPostedFile hpf = context.Request.Files[file] as HttpPostedFile;
            if (hpf.ContentLength == 0)
            savedFileName = context.Server.MapPath(context.Session["FileUpload"].ToString());
Posted 22-Dec-12 9:07am
Updated 22-Dec-12 9:09am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi, first of all you must mark you handler with IRequiresSessionState interface.
This is only markable attribute, hence you don't need to inherit some additional methods in your handler.
Try to do that , and in fact you will reach access to Session data within your HttpHandler.
Pepin z Hane 23-Dec-12 14:14pm
From which library IRequiresSessionState is? It didn't find any...
Oleksandr Kulchytskyi 23-Dec-12 14:32pm
Is it so hard to open MSDN and search all about IRequiresSessionState ?)
Namespace: System.Web.SessionState, Assembly :System.Web.dll.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 22 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100