473,372 Members | 976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

HttpContext.Current.Session is null

After some digging, I discovered HttpContext.Current.Session is null
when trying to access a session variable, username, in my upload.cs
code which is in the App_Code folder.

I just determined that I can't because HttpContext.Current.Session is
null. (HttpContext.Current is fine though)

I think there may be another server side method interfering with my
ability to access the session.

Is there any other way to share a variable with my default.aspx page?

If anyone can help, here is the code for upload.cs:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Web.Services;

public class Upload : IHttpHandler
{
string m_username;
public Upload()
{
// I've placed the code to set the session variable in different
locations
// no matter where I cannot get it. HttpContext.Current.Session is
NULL??
string m_username="";
if (null != HttpContext.Current && null !=
HttpContext.Current.Session &&
null != HttpContext.Current.Session["username"]){
m_username=HttpContext.Current.Session["username"].ToString();
m_username=m_username+"\\";
}
}
#region IHttpHandler Members
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count 0)
{
// get the applications path
string tempFile = context.Request.PhysicalApplicationPath;
// loop through all the uploaded files
for(int j = 0; j < context.Request.Files.Count; j++)
{
HttpPostedFile uploadFile = context.Request.Files[j];
if (uploadFile.ContentLength 0)
{
uploadFile.SaveAs(string.Format("{0}{1}{2}",
tempFile, "Upload\\" + m_username , uploadFile.FileName));

}
}
}
HttpContext.Current.Response.Write(" ");
}

#endregion
}

May 16 '07 #1
2 11899

Do you have anything in your web.config related to http modules? I
had this problem once when I added a <clear /element to the http
modules not realizing that many of the asp.net functionality depended
on modules defined in the machine config.

HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On 16 May 2007 13:25:30 -0700, Dave <on********@gmail.comwrote:
>After some digging, I discovered HttpContext.Current.Session is null
when trying to access a session variable, username, in my upload.cs
code which is in the App_Code folder.

I just determined that I can't because HttpContext.Current.Session is
null. (HttpContext.Current is fine though)

I think there may be another server side method interfering with my
ability to access the session.
May 16 '07 #2

"Dave" <on********@gmail.comwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...
After some digging, I discovered HttpContext.Current.Session is null
when trying to access a session variable, username, in my upload.cs
code which is in the App_Code folder.

I just determined that I can't because HttpContext.Current.Session is
null. (HttpContext.Current is fine though)

I think there may be another server side method interfering with my
ability to access the session.

Is there any other way to share a variable with my default.aspx page?

If anyone can help, here is the code for upload.cs:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Web.Services;

public class Upload : IHttpHandler
{
string m_username;
public Upload()
{
// I've placed the code to set the session variable in different
locations
// no matter where I cannot get it. HttpContext.Current.Session is
NULL??
string m_username="";
if (null != HttpContext.Current && null !=
HttpContext.Current.Session &&
null != HttpContext.Current.Session["username"]){
m_username=HttpContext.Current.Session["username"].ToString();
m_username=m_username+"\\";
}
}
#region IHttpHandler Members
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count 0)
{
// get the applications path
string tempFile = context.Request.PhysicalApplicationPath;
// loop through all the uploaded files
for(int j = 0; j < context.Request.Files.Count; j++)
{
HttpPostedFile uploadFile = context.Request.Files[j];
if (uploadFile.ContentLength 0)
{
uploadFile.SaveAs(string.Format("{0}{1}{2}",
tempFile, "Upload\\" + m_username , uploadFile.FileName));

}
}
}
HttpContext.Current.Response.Write(" ");
}

#endregion
}
You need to implement IRequiresSessionState or IReadOnlySessionState

e.g.

public class Upload : IHttpHandler, IReadOnlySessionState
May 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: moondaddy | last post by:
I need to set a variable to a session variable (if that's what you call it) like this: dim ds as dataset = HttpContext.Current.Session("CustDataSet") But I get an exception if this variable...
2
by: midgetgem | last post by:
I'm storing a DataTable in a session object and call a seperate class with a method in it to work with. How do I access the session from this class? I was using HttpContext.Current.Session,...
3
by: goelajay | last post by:
I have a web service where I am using System.Web.HttpContext.Current.Session. If I post an xmlrequest using an aspx page, I can referrence the Session value, but If I am posting it from say a vbs...
0
by: Aaron Morton | last post by:
I'm working on a IHttpModule that handles the PreSendRequestHeaders event from the HttpApplication, if the event is raised after EndRequest then HttpContext.Current is null. If it is raised before...
8
by: eric | last post by:
I have a 2.0 asp.net project. In a class contained within a seperate project, I am trying to reference HttpContext.Current.Session but Session is always null. I've tried implementing...
14
by: R.A.M. | last post by:
Hello, I have created ASP.NET project in which I have a file Admin.cs. It contains static class Admin with some methods and properties. The problem is that in property get a reference...
0
by: alister7 | last post by:
hi every1 im trying to download a music file from the database SQLserver.which i upload in the database.. The Code below works fine in wen i create a new project of an ASP.Net web application..m...
3
by: Madhur | last post by:
Hello I am delivering an asp.net 2.0 application to my customer. I need to know, If I need to check for the condition of HttpContext.Current to be null in my business logic. I have extensively...
0
by: SujaShyam | last post by:
In our application we have to access session objects in business class. We are using HttpContext.Current.Session to get the session value. In some cases it returns the value but mostly its throwing a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.