How to get the session-object within an IHttpHandler

A

Aartware

I've read all the items about the IHttpHandler and the session-object
and I see nothing wrong with my code, but still I have no session
object.

This is my code:
Imports System
Imports System.Data
Imports System.Web
imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.IO

Public Class Upload
Implements IHttpHandler
Implements IRequiresSessionState

'Public Sub ProcessRequest(ByVal context As HttpContext) Implements
IHttpHandler
'Implements IRequiresSessionState

'Public Sub ProcessRequest(ByVal context As HttpContext) Implements
System.Web.IHttpHandler.ProcessRequest',
system.web.sessionstate.IRequiresSessionState
Public Overridable Sub ProcessRequest(ByVal context As HttpContext)
Implements IHttpHandler.ProcessRequest
Dim objSession As HttpSessionState = context.current.Session
If context.Request.Files.Count > 0 Then
Dim tempFile As String = context.Request.PhysicalApplicationPath
Dim j As Integer = 0
While j < context.Request.Files.Count
Dim uploadFile As HttpPostedFile = context.Request.Files(j)
If uploadFile.ContentLength > 0 Then
try
Dim outputdir As string = objSession("dir") & ""

Dim sUploadDir as string = "\\fileserver\test2\"
if outputdir.length > 0 Then
uploadFile.SaveAs(outputdir & uploadFile.FileName)
Else
uploadFile.SaveAs(sUploadDir & uploadFile.FileName)
End If
catch ex as exception
Dim sOut as string = "uploaderror.log"

If File.Exists(sOut) Then File.Delete (sOut)
Dim sw As StreamWriter = New StreamWriter(sOut)
sw.WriteLine (ex.tostring)
sw.Close()
end try
End If
j += 1
End While
End If
HttpContext.Current.Response.Write(" ")
End Sub

Public Overridable ReadOnly Property IsReusable() As Boolean
Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class

My web.config looks like:
<httpHandlers>
<remove verb="POST,GET" path="Upload.axd"/>
<add verb="POST,GET" path="Upload.axd" type="Upload"/>

</httpHandlers>
<httpRuntime maxRequestLength="1550000"/>
<sessionState mode="StateServer"
stateConnectionString="tcpip=127.0.0.1:42424"
cookieless="false"
timeout="200"/>

The start aspx looks like:
<%@ Page Language="VB" AutoEventWireup="true" enableviewstate="true"
AspCompat="false" Trace="false" Debug="true"%>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.Common" %>
<script language="VB" runat="server">

Sub Page_Load(sender as Object, e as EventArgs)
Session("dir")= "\\server\test1\"
End Sub

No error appears, but all the uploaded files are uploaded in the
test2-directory, but I want them in the directory what is set in the
session-object.

I've started with IIS 5, but now I'm testing with IIS 6. But it's not
making any difference.

I'm hoping that someone can tell me what I've forgotten or what I'm
doing wrong.

Is there anybody out there, who can help me???
 
A

Aartware

The reason why I don't have my session is because of the redirecting
object is not my aspx-page but a flash object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top