M
Matt Jensen
Howdy
I've got a rather strange issue occuring.
I used forms based .NET authentication, although I'm also setting some
session variables when people login.
However, I've found when people use one of my webform pages which includes a
button that pops up a window where you can upload files, if you upload files
in this popup window, it seems to somehow clear out all of the session
variables and the users get logged out. However, if people don't upload
files, then their use of the webform page proceeds as required/expected.
I'm planning to phase out the session variables by upgrading my code,
however I can't understand this problem which seems quite strange and I'd
like to know what the problem is.
Any clues would be greatly appreciated.
Cheers
Matt
If it helps, here is code in question:
The main part of the code behind for the upload page:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack) {
pnlUpload.Visible = true;
pnlUploaded.Visible = false;
}
if (IsPostBack) {
pnlUpload.Visible = false;
pnlUploaded.Visible = true;
}
strJobRequestID = Request.QueryString["JobRequestID"];
btnClose2.Attributes.Add("onclick", "return closeupdate();");
}
public void UploadFile(object Sender,EventArgs E) { //Event handler for
the upload button
lblFileList.Text = "";
if (Request.Files.Count > 0) { //if there are files attached
//Get directory path
string strDirPath = Server.MapPath(".\\" + "/../../detail/files/" +
strJobRequestID + "/");
//Response.Write(strDirPath);
//if Directory path doesn't exist then create it
if (!Directory.Exists(strDirPath)) {
Directory.CreateDirectory(strDirPath);
}
//Iterate through the Request.Files collection
for(IntLoop=0; IntLoop<Request.Files.Count; IntLoop++) {
if (Request.Files[IntLoop] !=null) { //Checking for valid file
// Since the FileName gives the entire path we use Substring function
to get the filename (including the file extension).
string StrFileName =
Request.Files[IntLoop].FileName.Substring(Request.Files[IntLoop].FileName.LastIndexOf("\\")
+ 1);
string StrFileType = Request.Files[IntLoop].ContentType;
int IntFileSize = Request.Files[IntLoop].ContentLength;
//Check for file length > 0 and Upload if it is
if (IntFileSize > 0) {
//Save the file to the web server
string filePath = (strDirPath + "/" + StrFileName);
Request.Files[IntLoop].SaveAs(filePath);
lblFileList.Text += "<li>" + StrFileName + "</li>";
}
}
}
}
}
Here is the main code for the webform. Notice the "multipart/form-data" -
could that be causing the problem somehow?
<form id="JBSv4ServerForm" enctype="multipart/form-data" runat="server">
<div class=JBSv4PopupBody>
<!--begin of body-->
<div class=JBSv4PopupMainBody>
<div class=JBSv4JobListing><aspanel id=pnlUpload runat="server">
<div class="JBSv4JobListingHeader">
<h3>Attach files to job <%if
(!Request.QueryString["JobRequestID"].StartsWith("Temp"))
{%><%=Request.QueryString["JobRequestID"]%><% } %></h3></div>
<table class="JBSv4JobListingTable">
<tr>
<td><input id="File1" type="file" size="30" name="File1"
runat="server"></td>
<td class="listsTableRight" valign="top" rowspan="5">
<p>Use the 'Browse' buttons to select up to five files, then click
'Upload
files'.</p>
<p>You'll be able to attach more files afterwards if you need
to.</p></td></tr>
<tr>
<td><input id="File2" type="file" size="30" name="File2"
runat="server"></td></tr>
<tr>
<td><input id="File3" type="file" size="30" name="File3"
runat="server"></td></tr>
<tr>
<td><input id="File4" type="file" size="30" name="File4"
runat="server"></td></tr>
<tr>
<td><input id="File5" type="file" size="30" name="File5"
runat="server"></td></tr>
<tr>
<td colspan="2"><input class="formbutton" onclick="closewindow();"
type="button" value="Close window" name="btnCloseWindow">
<asp:button id="CmdUpload" onclick="UploadFile" runat="server"
cssclass="formbutton" text="Upload
files"></asp:button></td></tr></table></aspanel><aspanel
id=pnlUploaded runat="server">
<div class="JBSv4JobListingHeader">
<h3>Files attached</h3></div>
<table class="JBSv4JobListingTable">
<tr>
<td>
<p>The following files have been attached:</p>
<ul>
<asp:label id="lblFileList" runat="server"></asp:label></ul>
<p><strong>Please note: </strong>Use the 'Close Window' button below
when
you are finished which will close this window AND refresh the job
attachments list.</p>
<asp:button id="btnClose2" runat="server" cssclass="formbutton" text="Close
window"></asp:button>
<asp:button id="btnAttachMore" runat="server" cssclass="formbutton"
text="Attach more files"></asp:button></td></tr></table></aspanel></DIV>
<!--end of body--></DIV></DIV></FORM>
I've got a rather strange issue occuring.
I used forms based .NET authentication, although I'm also setting some
session variables when people login.
However, I've found when people use one of my webform pages which includes a
button that pops up a window where you can upload files, if you upload files
in this popup window, it seems to somehow clear out all of the session
variables and the users get logged out. However, if people don't upload
files, then their use of the webform page proceeds as required/expected.
I'm planning to phase out the session variables by upgrading my code,
however I can't understand this problem which seems quite strange and I'd
like to know what the problem is.
Any clues would be greatly appreciated.
Cheers
Matt
If it helps, here is code in question:
The main part of the code behind for the upload page:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack) {
pnlUpload.Visible = true;
pnlUploaded.Visible = false;
}
if (IsPostBack) {
pnlUpload.Visible = false;
pnlUploaded.Visible = true;
}
strJobRequestID = Request.QueryString["JobRequestID"];
btnClose2.Attributes.Add("onclick", "return closeupdate();");
}
public void UploadFile(object Sender,EventArgs E) { //Event handler for
the upload button
lblFileList.Text = "";
if (Request.Files.Count > 0) { //if there are files attached
//Get directory path
string strDirPath = Server.MapPath(".\\" + "/../../detail/files/" +
strJobRequestID + "/");
//Response.Write(strDirPath);
//if Directory path doesn't exist then create it
if (!Directory.Exists(strDirPath)) {
Directory.CreateDirectory(strDirPath);
}
//Iterate through the Request.Files collection
for(IntLoop=0; IntLoop<Request.Files.Count; IntLoop++) {
if (Request.Files[IntLoop] !=null) { //Checking for valid file
// Since the FileName gives the entire path we use Substring function
to get the filename (including the file extension).
string StrFileName =
Request.Files[IntLoop].FileName.Substring(Request.Files[IntLoop].FileName.LastIndexOf("\\")
+ 1);
string StrFileType = Request.Files[IntLoop].ContentType;
int IntFileSize = Request.Files[IntLoop].ContentLength;
//Check for file length > 0 and Upload if it is
if (IntFileSize > 0) {
//Save the file to the web server
string filePath = (strDirPath + "/" + StrFileName);
Request.Files[IntLoop].SaveAs(filePath);
lblFileList.Text += "<li>" + StrFileName + "</li>";
}
}
}
}
}
Here is the main code for the webform. Notice the "multipart/form-data" -
could that be causing the problem somehow?
<form id="JBSv4ServerForm" enctype="multipart/form-data" runat="server">
<div class=JBSv4PopupBody>
<!--begin of body-->
<div class=JBSv4PopupMainBody>
<div class=JBSv4JobListing><aspanel id=pnlUpload runat="server">
<div class="JBSv4JobListingHeader">
<h3>Attach files to job <%if
(!Request.QueryString["JobRequestID"].StartsWith("Temp"))
{%><%=Request.QueryString["JobRequestID"]%><% } %></h3></div>
<table class="JBSv4JobListingTable">
<tr>
<td><input id="File1" type="file" size="30" name="File1"
runat="server"></td>
<td class="listsTableRight" valign="top" rowspan="5">
<p>Use the 'Browse' buttons to select up to five files, then click
'Upload
files'.</p>
<p>You'll be able to attach more files afterwards if you need
to.</p></td></tr>
<tr>
<td><input id="File2" type="file" size="30" name="File2"
runat="server"></td></tr>
<tr>
<td><input id="File3" type="file" size="30" name="File3"
runat="server"></td></tr>
<tr>
<td><input id="File4" type="file" size="30" name="File4"
runat="server"></td></tr>
<tr>
<td><input id="File5" type="file" size="30" name="File5"
runat="server"></td></tr>
<tr>
<td colspan="2"><input class="formbutton" onclick="closewindow();"
type="button" value="Close window" name="btnCloseWindow">
<asp:button id="CmdUpload" onclick="UploadFile" runat="server"
cssclass="formbutton" text="Upload
files"></asp:button></td></tr></table></aspanel><aspanel
id=pnlUploaded runat="server">
<div class="JBSv4JobListingHeader">
<h3>Files attached</h3></div>
<table class="JBSv4JobListingTable">
<tr>
<td>
<p>The following files have been attached:</p>
<ul>
<asp:label id="lblFileList" runat="server"></asp:label></ul>
<p><strong>Please note: </strong>Use the 'Close Window' button below
when
you are finished which will close this window AND refresh the job
attachments list.</p>
<asp:button id="btnClose2" runat="server" cssclass="formbutton" text="Close
window"></asp:button>
<asp:button id="btnAttachMore" runat="server" cssclass="formbutton"
text="Attach more files"></asp:button></td></tr></table></aspanel></DIV>
<!--end of body--></DIV></DIV></FORM>