471,570 Members | 998 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

How to get the session-object within an IHttpHandler

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???

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

Dec 20 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Damien | last post: by
1 post views Thread by mudge | last post: by
reply views Thread by joseph conrad | last post: by
7 posts views Thread by aroraamit81 | last post: by
reply views Thread by TRB_NV | last post: by
2 posts views Thread by Gordon Burditt | last post: by
3 posts views Thread by mikeboston | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.