I am trying to get the session value from a FileSystemHandler.ashx
that I have in my project, but it's not returning anything.
'This is the relevant line of code
Dim str As String = DirectCast(_context.Request.QueryString("SessionID"),String)
Here is the method:
Public Sub ProcessRequest(ByVal context__1 As HttpContext) Implements IHttpHandler.ProcessRequest
Context = context__1
If Context.Request.QueryString("path") Is Nothing Then
Exit Sub
End If
'Get the SessionState
Dim str As String = DirectCast(_context.Request.QueryString("SessionID"),String)
Initialize()
Dim virtualPathToFile As String = Context.Server.HtmlDecode(Context.Request.QueryString("path"))
Dim physicalPathToFile As String = ""
For Each mappedPath As KeyValuePair(Of String, String) In mappedPathsInConfigFile
If virtualPathToFile.ToLower().StartsWith(mappedPath.Key.ToLower()) Then
' Build the physical path to the file ;
physicalPathToFile = virtualPathToFile.Replace(mappedPath.Key, mappedPath.Value).Replace("/", "\")
' Break the foreach loop
Exit For
End If
Next
'The docx files are downloaded
If Path.GetExtension(physicalPathToFile).Equals(".docx", StringComparison.CurrentCultureIgnoreCase) Then
' Handle .docx files ;
Me.WriteFile(physicalPathToFile, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", Context.Response)
End If
If Path.GetExtension(physicalPathToFile).Equals(".jpg", StringComparison.CurrentCultureIgnoreCase) Then
' Handle .jpg files ;
WriteFile(physicalPathToFile, "image/jpeg", Context.Response)
End If
' "txt/html" is the default value for the Response.ContentType property
' Do not download the file. Open in the window
Context.Response.WriteFile(physicalPathToFile)
End Sub
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.SessionState
Imports System.Collections.Generic
Imports System.Xml
Imports DispatchSoftware
Imports System.IO
Public Class FileSystemHandler
Implements IHttpHandler
#Region "IHttpHandler Members"
Private pathToConfigFile As String = "~/Incidents/MappingFile.mapping"
**Private _context As HttpContext
Private m_IncidentPath As String = Nothing
Private m_SessionID As String
Private Property Context() As HttpContext
Get
Return _context
End Get
Set(ByVal value As HttpContext)
_context = value
End Set
End Property**
Dim _itemHandlerPath As String
Dim mappedPathsInConfigFile As Dictionary(Of String, String)
Private Sub Initialize()
If Not String.IsNullOrEmpty(Me.Context.Request.QueryString("SessionID")) Then
m_SessionID = Me.Context.Request.QueryString("SessionID")
End If
If Not String.IsNullOrEmpty(Sessions.GetKeyValueSessionFile(m_SessionID, "IRPicturesPath")) Then
m_IncidentPath = (Sessions.GetKeyValueSessionFile(m_SessionID, "IRPicturesPath"))
End If
Dim configFile As New XmlDocument()
Dim physicalPathToConfigFile As String = Context.Server.MapPath(Me.pathToConfigFile)
configFile.Load(physicalPathToConfigFile)
' Load the configuration file
Dim rootElement As XmlElement = configFile.DocumentElement
Dim handlerPathSection As XmlNode = rootElement.GetElementsByTagName("genericHandlerPath")(0)
' get all mappings ;
Me._itemHandlerPath = handlerPathSection.InnerText
Me.mappedPathsInConfigFile = New Dictionary(Of String, String)()
Dim mappingsSection As XmlNode = rootElement.GetElementsByTagName("Mappings")(0)
' get all mappings ;
For Each mapping As XmlNode In mappingsSection.ChildNodes
Dim virtualPathAsNode As XmlNode = mapping.SelectSingleNode("child::VirtualPath")
Dim physicalPathAsNode As XmlNode = mapping.SelectSingleNode("child::PhysicalPath")
Me.mappedPathsInConfigFile.Add(PathHelper.RemoveEndingSlash(virtualPathAsNode.InnerText, "/"c), PathHelper.RemoveEndingSlash(physicalPathAsNode.InnerText, "\"c))
Next
End Sub