D
Dave
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
}
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
}