Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > HttpContext.Current.Session is null

Reply
Thread Tools

HttpContext.Current.Session is null

 
 
Dave
Guest
Posts: n/a
 
      05-16-2007
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
}

 
Reply With Quote
 
 
 
 
Samuel R. Neff
Guest
Posts: n/a
 
      05-16-2007

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 <(E-Mail Removed)> wrote:

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


 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      05-16-2007

"Dave" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
createImage sometime returns null and sometime returns non-null. vizlab Java 3 10-17-2007 11:21 AM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
difference between null object and null string gokul.b@gmail.com Java 16 10-12-2005 06:43 PM
VB.NET Null to SQL Null (ASP.NET 2.0 GridView) Kivak Wolf ASP .Net 2 06-28-2005 02:01 PM
Is there a null ostream (like /dev/null) in cpp? Bo Peng C++ 13 07-18-2004 07:17 PM



Advertisments