473,473 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 11921

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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.