Showing posts with label forms. Show all posts
Showing posts with label forms. Show all posts

Thursday, March 29, 2012

Session Values are lost

Hello everyone,

I have a problem I have no idea why it happens.
I have an ASP.NET application that has around 7 forms.
To move from one form to another I use "redirect".
I also use around 12 Session items that I fill with different values
like for ex.: Session.item("EmployeeName")="LILIA"
98% of the time everything is OK.
However once "in a blue moon" I find that the value in
Session.item("EmployeeName") is lost.
I am sure is not an expiration time since this happens after only a
couple of minutes.
Any help will be very much appreciated.

Thanks,

LilianaIf you are convinced that it isn't the timout its almost for sure that the
application gets restarted for some reason.
Causes are editing wec.config,gloval.asax,...

Cheers,
Tom Pester

> Hello everyone,
> I have a problem I have no idea why it happens.
> I have an ASP.NET application that has around 7 forms.
> To move from one form to another I use "redirect".
> I also use around 12 Session items that I fill with different values
> like for ex.: Session.item("EmployeeName")="LILIA"
> 98% of the time everything is OK.
> However once "in a blue moon" I find that the value in
> Session.item("EmployeeName") is lost.
> I am sure is not an expiration time since this happens after only a
> couple of minutes.
> Any help will be very much appreciated.
> Thanks,
> Liliana
You must be sure follow issues:
1.Would you modify your application's bin directory.
2.May be your aspnet_wp.exe(in window2000 or xp) was recycled.
--
Help you,Help me.

"LiliA" wrote:

> Hello everyone,
> I have a problem I have no idea why it happens.
> I have an ASP.NET application that has around 7 forms.
> To move from one form to another I use "redirect".
> I also use around 12 Session items that I fill with different values
> like for ex.: Session.item("EmployeeName")="LILIA"
> 98% of the time everything is OK.
> However once "in a blue moon" I find that the value in
> Session.item("EmployeeName") is lost.
> I am sure is not an expiration time since this happens after only a
> couple of minutes.
> Any help will be very much appreciated.
> Thanks,
> Liliana
>

Thursday, March 22, 2012

session variables

Hi all, I'm having a problem transferring session variable values between web forms. I'm storing them like so...

if intID <> 0 then
Session("EmployeeID") = intID
FormsAuthentication.RedirectFromLoginPage(intID, false)
Response.Redirect("Webform2.aspx")

I've checked and the value is being stored ok - it can be printed out on this form. However on my second form I have this...

txtID.Text = HttpContext.Current.Session("EmployeeID")

...but the value is not retrieved. I've tried it with cookies and with ViewState as well and can't get anything to pass the values over.
Any help much appreciated!Hmm, if no state saving mechanism (cookies, viewstate, session, etc) is holding a value, then I would say that there is a problem with the flow of how the code executes. Ie, you're requesting the value before it's been initialized. Perhaps posting the necessary code for both pages would help clarify the problem.
Hello, try to use

HttpContext.Current.Session("EmployeeID").ToString()

regards
I'm passing two strings (username, password) to a business object which returns an integer (employeeID). The following procedure is called when the user clicks a button to login. It is working fine and if I disable the link, put a textbox on the page and call the session variable, the value is there all right...


<%@. Import namespace="UserAuthentication" %>
<%@. Page Language="vb" EnableSessionState="True" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="InventoryManager.WebForm1"%>
<%@. Register TagPrefix="Inventory" TagName="Footer" src="http://pics.10026.com/?src=footer.ascx" %>
<%@. Register TagPrefix="Inventory" TagName="Header" src="http://pics.10026.com/?src=header.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<script runat="server"
sub Login(obj as object, e as EventArgs)

' UserAuthentication is the namespace name
' AuthenticateUser is the class inside it
dim objUser as New UserAuthentication.AuthenticateUser
dim intID as integer

' Login is a method of the AuthenticateUser class
intID = objUser.Login(txtUserName.Text, txtPassword.Text)

if intID <> 0 then

Session("EmployeeID") = intID
FormsAuthentication.RedirectFromLoginPage(intID, false)
Response.Redirect("Webform2.aspx")
else
lblMessage.Visible = True
lblMessage.Text="Invalid Login"
end if

end sub

</script>


Then on the page this redirects to...

Imports System.Web.Security ' Required Class for Authentication
Imports System.Data ' DB Accessing Import
Imports System.Data.OleDb ' Access Database Required Import
Imports System.Configuration ' Required for Web.Config appSettings
Imports System.Web

Public Class WebForm2

Inherits System.Web.UI.Page
Dim MyConn As OleDbConnection = New OleDbConnectio(ConfigurationSettings.AppSettings("strConn"))

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then

' Fill the Listbox with Product Items
ListLoad()
MyConn.Close()
txtID.Text = HttpContext.Current.Session("EmployeeID")
End If

txtID.Text = HttpContext.Current.Session("EmployeeID")

End Sub


But this doesn't retrieve the value.
OK haider, I'll try that this evening.
ok, please do test it and reply back to me, to follow up with you. there shouldn't be any problem.

regards
Sorry haider, that didn't work either.

Hello,

I am having similar problems. I store a value in a session variable from a textbox - Session("IDate") = textbox1.text

The value is in the session variable. I then call the new page with this Response.Redirect("Newpage.aspx")

On the new page I am trying to store the value into another text box, but no value is there. I can issue a Response.Writre(Session("IDate")) and the value is displayed. But if I use tbxStartDate.Text = Session("IDate").ToString() the value is not entered in the text box. Any suggestions?

Mike

Tuesday, March 13, 2012

Session variables disappear in relation to a file upload

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><asp:panel 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></asp:panel><asp:panel
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></asp:panel></DIV>
<!--end of body--></DIV></DIV></FORM>Hi Matt,
Looks like your appdomain is recycling.
You may check that using Perfmon and application restrats counter to verify
if your appdomain is recycling.
Also, what is the size of the file which causes the issues? Is it each and
every file which causes the session to recycle'
Thanks,
Rahul Soni
-->The secret to creativity is knowing how to hide your sources<--
"Matt Jensen" wrote:

> 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 fil
es
> 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 functio
n
> 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><asp:panel 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></asp:panel><asp:panel
> 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="Clos
e
> window"></asp:button>
> <asp:button id="btnAttachMore" runat="server" cssclass="formbutton"
> text="Attach more files"></asp:button></td></tr></table></asp:panel></DIV>
> <!--end of body--></DIV></DIV></FORM>
>
>
Thanks Rahul
Hmm, application restarts are 807 and Requests Queued is 54,000!!!!
And the error occurred for 1 file of 1KB too.
Actually seems to be the code below that's causing the problem, which
renames the file upload directory from a temporary name to the ID number of
the job request (because the webform page in question is for logging a job,
and the directory path ID number is not known until the job is logged):
//JOB FILES (if they exist)
//Root directory path for JBS job files
string strDirPath = Server.MapPath(".\\" + "/../../detail/files/");
//Response.Write(strDirPath+"<br>");
//New Directory path for logged job files
JBSv4.utils.jbs.v4.utils.utils utilsClass1 = new
JBSv4.utils.jbs.v4.utils.utils();
strLongJobRequestID = utilsClass1.LongJobNumber(intJobRequestID);
string strDirPathJobNo = strDirPath + strLongJobRequestID + "\\";
//Response.Write(strDirPathJobNo+"<br>");
//Directory path used for temporary file storage before JobRequestID
was created
strTempJobRequestID = tbxTempID.Text;
string strDirPathTemp = strDirPath + strTempJobRequestID + "\\";
//Response.Write(strDirPathTemp+"<br>");
//Rename temporary file storage directory (if it exists) to job number
directory
if (Directory.Exists(strDirPathTemp)) {
Directory.Move(strDirPathTemp, strDirPathJobNo);
}
What do I do?
Thanks again for any more help.
Matt
"Rahul Soni" <RahulSoni@.discussions.microsoft.com> wrote in message
news:1EC073F3-5409-42D9-9E75-A5C368CF6512@.microsoft.com...
> Hi Matt,
> Looks like your appdomain is recycling.
> You may check that using Perfmon and application restrats counter to
> verify
> if your appdomain is recycling.
> Also, what is the size of the file which causes the issues? Is it each and
> every file which causes the session to recycle'
> --
> Thanks,
> Rahul Soni
> -->The secret to creativity is knowing how to hide your sources<--
>
> "Matt Jensen" wrote:
>
On further investigation, it is this code
if (Directory.Exists(strDirPathTemp)) {
Directory.Move(strDirPathTemp, strDirPathJobNo);
}
causing the problem, and I note that when this code runs (and the user gets
logged out), the counter for application restarts increases by 1.
I'm reading something that makes me think that maybe some virus checking
software is involved in the problem.
Thoughts?
Cheers
Matt
"Matt Jensen" <replytonewsgroups@.microsoft.com> wrote in message
news:uB7Ny7z%23FHA.924@.TK2MSFTNGP12.phx.gbl...
> Thanks Rahul
> Hmm, application restarts are 807 and Requests Queued is 54,000!!!!
> And the error occurred for 1 file of 1KB too.
> Actually seems to be the code below that's causing the problem, which
> renames the file upload directory from a temporary name to the ID number
> of the job request (because the webform page in question is for logging a
> job, and the directory path ID number is not known until the job is
> logged):
> //JOB FILES (if they exist)
> //Root directory path for JBS job files
> string strDirPath = Server.MapPath(".\\" + "/../../detail/files/");
> //Response.Write(strDirPath+"<br>");
> //New Directory path for logged job files
> JBSv4.utils.jbs.v4.utils.utils utilsClass1 = new
> JBSv4.utils.jbs.v4.utils.utils();
> strLongJobRequestID = utilsClass1.LongJobNumber(intJobRequestID);
> string strDirPathJobNo = strDirPath + strLongJobRequestID + "\\";
> //Response.Write(strDirPathJobNo+"<br>");
> //Directory path used for temporary file storage before JobRequestID
> was created
> strTempJobRequestID = tbxTempID.Text;
> string strDirPathTemp = strDirPath + strTempJobRequestID + "\\";
> //Response.Write(strDirPathTemp+"<br>");
> //Rename temporary file storage directory (if it exists) to job number
> directory
> if (Directory.Exists(strDirPathTemp)) {
> Directory.Move(strDirPathTemp, strDirPathJobNo);
> }
> What do I do?
> Thanks again for any more help.
> Matt
>
> "Rahul Soni" <RahulSoni@.discussions.microsoft.com> wrote in message
> news:1EC073F3-5409-42D9-9E75-A5C368CF6512@.microsoft.com...
>
This appears to be by 'design'...!!
http://groups.google.co.uk/group/mi...1f03aac74f80ba6
Solved using the code on this page:
http://blogs.msdn.com/korbyp/archiv...2/19/76411.aspx
Still wondering though what it means that my Requests Queued is 54,000!?
Thanks for any advice
Cheers
Matt
"Matt Jensen" <replytonewsgroups@.microsoft.com> wrote in message
news:%23zcjvF0%23FHA.3104@.TK2MSFTNGP15.phx.gbl...
> On further investigation, it is this code
> if (Directory.Exists(strDirPathTemp)) {
> Directory.Move(strDirPathTemp, strDirPathJobNo);
> }
> causing the problem, and I note that when this code runs (and the user
> gets logged out), the counter for application restarts increases by 1.
> I'm reading something that makes me think that maybe some virus checking
> software is involved in the problem.
> Thoughts?
> Cheers
> Matt
> "Matt Jensen" <replytonewsgroups@.microsoft.com> wrote in message
> news:uB7Ny7z%23FHA.924@.TK2MSFTNGP12.phx.gbl...
>