Showing posts with label files. Show all posts
Showing posts with label files. Show all posts

Thursday, March 29, 2012

session value lost

Hello NG,

I have three files (default.aspx, search.aspx and work.aspx). The way
is: login on default (if session is newsession). The loginname I write
into as sessionvariable (username). So I redirect to my search.aspx.
Here I have a form which allows fill in some fields (place, street,
name etc.). With this informations i build a sqlquerey for sqlserver,
fill a datagrid and after select the right record by usin a link behind
I save the recordid to the session and redirect to work.aspx. With a
new sqlstring I fetch the data from the sqlserver. But this data is
only to display. The user can edit Data for a new record in anoter
table and end it wiht button click. Here I will save all sessionvalues
(username, and recordinformation) with sqlstring and redirect to
search.aspx.

Now the problems:
1. I don't no what I've changed - but I have to...
After redirection from work to search I've got an sql-error. The string
will be cleard before building new, so why does it run once, but not
after redirect?
2. I solved this problem with redirecting from work to default. Its
running. But: the session username is empty - why?
3. I solved with writing the username in an hidden field on
default.aspx, read it again and write to session. Everything is fine.
4. Now we can work, and I will change the username from manuel login to
reading from client windows. But I realy want to know why I have the
Problems 1 to 3 and problem no 4 is: some stored records have no
username within. Who can explain it to me - who as a solution to solve
the problems?You might want to share the source code for your search.aspx page so
we can look it over.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On 27 Jun 2005 07:46:30 -0700, "catweezle2010" <catweezle2010@.gmx.de>
wrote:

>Hello NG,
>I have three files (default.aspx, search.aspx and work.aspx). The way
>is: login on default (if session is newsession). The loginname I write
>into as sessionvariable (username). So I redirect to my search.aspx.
>Here I have a form which allows fill in some fields (place, street,
>name etc.). With this informations i build a sqlquerey for sqlserver,
>fill a datagrid and after select the right record by usin a link behind
>I save the recordid to the session and redirect to work.aspx. With a
>new sqlstring I fetch the data from the sqlserver. But this data is
>only to display. The user can edit Data for a new record in anoter
>table and end it wiht button click. Here I will save all sessionvalues
>(username, and recordinformation) with sqlstring and redirect to
>search.aspx.
>Now the problems:
>1. I don't no what I've changed - but I have to...
>After redirection from work to search I've got an sql-error. The string
>will be cleard before building new, so why does it run once, but not
>after redirect?
>2. I solved this problem with redirecting from work to default. Its
>running. But: the session username is empty - why?
>3. I solved with writing the username in an hidden field on
>default.aspx, read it again and write to session. Everything is fine.
>4. Now we can work, and I will change the username from manuel login to
>reading from client windows. But I realy want to know why I have the
>Problems 1 to 3 and problem no 4 is: some stored records have no
>username within. Who can explain it to me - who as a solution to solve
>the problems?
Hi Allen,

it will be to much code but I think, it's better for understanding:

I start with the default.aspx. If the session is new, nothing will
happen unless the user logs in - no problem. When I come from my last
page (call.aspx) the sessionvariable 'user' has still a value. When I
redirect to my second page (suche.aspx) this value will be lost. So I
do this workaround:

default.aspx

Sub Page_Load (ByVal Sender As Object, _
ByVal E As EventArgs)

Session("KD_VNAME")=""
Session("KD_NAME")=""
Session("STADT")=""
Session("PLZ")=""
Session("STRASSE")=""

If Session.IsNewSession Then
TextBox1.value="neu"
else
if ispostback then
Session("Anwendername") = TextBoxLogin.value
TextBox1.value=Session("Anwendername")
response.redirect("suche.aspx")
else
TextBox1.value=Session("Anwendername")
Session("Anwendername") = TextBox1.value
response.redirect("suche.aspx")
end if
end if

When loading the suche.aspx I check on newsession and if not I will
clear the value of some session varialbes:

suche.aspx

Sub Page_Load (ByVal Sender As Object, _
ByVal E As EventArgs)

If Session.IsNewSession Then
response.redirect("default.aspx")
else
dataSet
end if
end sub

public sub DataSet()
Session("KD_VNAME")=""
Session("KD_NAME")=""
Session("STADT")=""
Session("PLZ")=""
Session("STRASSE")=""
Datagrid1.DataBind()
end sub

After the user filled in the search date the function will be called.
First I had a redirect form my last page (call.aspx) back to this one.
If I am first on the page everything is fine. The second time, after
redirect I get an error, which means the sql statement is incorrect.
But there can no old value - I clear it. So I redirect to the
default.aspx:

function DatenSuche() As System.Data.IDataReader
Dim connectionString As String = "Data Source=mssql;Initial
Catalog=DB;User Id=huser;Password=passw;Connect Timeout=15;Network
Library=dbmssocn;"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim queryString As String = ""
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand

if TextBox_Name.text <> "" then
if queryString <> "" then
queryString = querystring & " and "
end if
queryString = queryString & "[KD_NAME] like N'" & TextBox_Name.text
& "%' "
end if
if TextBox_Vorname.text <> "" then
if queryString <> "" then
queryString = querystring & " and "
end if
queryString = queryString & "[KD_VNAME] like N'" &
TextBox_Vorname.text & "%' "
end if

queryString = "SELECT [View_Such].* FROM [View_Such] WHERE (" &
queryString & ")"
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)
Return dataReader
dataReader.close
dbConnection.close
connectionString = ""
queryString = ""
end function

call.aspx

public sub ButtonEnde_Click(sender As Object, e As EventArgs)
response.redirect("default.aspx")
'response.redirect("suche.aspx")
end sub

Any idea?
One thing you may want to try is to use:

Response.Redirect("page", False);

Whenever you are in a page where the user might have started a
session. See:
http://weblogs.asp.net/bleroy/archi.../03/207486.aspx

Another approach I'd try is to not use so many redirects, but drop a
panel control on your form and keep the search results inside the
panel. You can set the Visible property of the panel to false, and
toggle the value to true when there are search results to display.
This might make the page easier to work with.

--
Scott
http://www.OdeToCode.com/blogs/scott/]

On 29 Jun 2005 04:04:53 -0700, "catweezle2010" <catweezle2010@.gmx.de>
wrote:

>Hi Allen,
>it will be to much code but I think, it's better for understanding:
>I start with the default.aspx. If the session is new, nothing will
>happen unless the user logs in - no problem. When I come from my last
>page (call.aspx) the sessionvariable 'user' has still a value. When I
>redirect to my second page (suche.aspx) this value will be lost. So I
>do this workaround:
>default.aspx
>Sub Page_Load (ByVal Sender As Object, _
> ByVal E As EventArgs)
> Session("KD_VNAME")=""
> Session("KD_NAME")=""
> Session("STADT")=""
> Session("PLZ")=""
> Session("STRASSE")=""
>If Session.IsNewSession Then
> TextBox1.value="neu"
> else
> if ispostback then
> Session("Anwendername") = TextBoxLogin.value
> TextBox1.value=Session("Anwendername")
> response.redirect("suche.aspx")
> else
> TextBox1.value=Session("Anwendername")
> Session("Anwendername") = TextBox1.value
> response.redirect("suche.aspx")
> end if
> end if
>When loading the suche.aspx I check on newsession and if not I will
>clear the value of some session varialbes:
>suche.aspx
>Sub Page_Load (ByVal Sender As Object, _
> ByVal E As EventArgs)
>If Session.IsNewSession Then
> response.redirect("default.aspx")
> else
> dataSet
> end if
>end sub
>public sub DataSet()
>Session("KD_VNAME")=""
> Session("KD_NAME")=""
> Session("STADT")=""
> Session("PLZ")=""
> Session("STRASSE")=""
> Datagrid1.DataBind()
>end sub
>
>After the user filled in the search date the function will be called.
>First I had a redirect form my last page (call.aspx) back to this one.
>If I am first on the page everything is fine. The second time, after
>redirect I get an error, which means the sql statement is incorrect.
>But there can no old value - I clear it. So I redirect to the
>default.aspx:
>function DatenSuche() As System.Data.IDataReader
> Dim connectionString As String = "Data Source=mssql;Initial
>Catalog=DB;User Id=huser;Password=passw;Connect Timeout=15;Network
>Library=dbmssocn;"
> Dim dbConnection As System.Data.IDbConnection = New
>System.Data.SqlClient.SqlConnection(connectionStri ng)
> Dim queryString As String = ""
> Dim dbCommand As System.Data.IDbCommand = New
>System.Data.SqlClient.SqlCommand
> if TextBox_Name.text <> "" then
>if queryString <> "" then
> queryString = querystring & " and "
> end if
> queryString = queryString & "[KD_NAME] like N'" & TextBox_Name.text
>& "%' "
> end if
> if TextBox_Vorname.text <> "" then
> if queryString <> "" then
> queryString = querystring & " and "
> end if
> queryString = queryString & "[KD_VNAME] like N'" &
>TextBox_Vorname.text & "%' "
> end if
>
> queryString = "SELECT [View_Such].* FROM [View_Such] WHERE (" &
>queryString & ")"
> dbCommand.CommandText = queryString
> dbCommand.Connection = dbConnection
> dbConnection.Open
> Dim dataReader As System.Data.IDataReader =
>dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)
> Return dataReader
> dataReader.close
> dbConnection.close
> connectionString = ""
> queryString = ""
>end function
>
>call.aspx
>public sub ButtonEnde_Click(sender As Object, e As EventArgs)
> response.redirect("default.aspx")
> 'response.redirect("suche.aspx")
> end sub
>
>
>Any idea?

Monday, March 26, 2012

Session variable is not transferred to an asp page?

I have a asp.net project with all major pages written in aspx, but I want to keep an existing asp page in the same directory as the aspx files. But when the asp page gets loaded, the session variable is not recognized. Is this the case and why?To be specific, when I load the asp.net app using the address of http://localhost/myproj/ it works fine, and the asp page could read the session variable assigned by an aspx page. But if I use my computer name, say http://keystrokes_win2k/myproj/ then it doesn't work.

Any ideas?
No, the ASP and ASP.NET sessions are two separate objects that do not share their data. There are some third party session objects that you can use to communicate between the two environments, though.
What is the third party session object, please provide some lead ?

Thursday, March 22, 2012

Session Variables

Hi,

I am using .asp and .aspx files together on the same application. I would like to use Session variables with a .asp file. Will this work? Can I use Session variables with a .asp and .asax file? Or will global .asa work?

I haven't started coding yet. I thought I would save myself some time and ask first. Any suggestions are appreciated.

Thanks,

MikeHi there,

There are several articles our there that explain the tweeks you need to do to share sessions between asp and asp.net... here are some of them:

http://www.eggheadcafe.com/articles/20021207.asp

http://www.asp101.com/articles/sidney/sharingsessionstate/default.asp

I hope this helps,

Covo

Session Variables - Loosing

Hi,
I am using a web application -asp, ado, C#, using CodeBehind files etc..

I am using "InProc" session state and find that session variables are
loosing their values between one web form and the next. I have used "InProc"
on my development machine and the session variable values are being
maintained between pages.

I copied two of the relevant forms into another application and using
"InProc" session state they maintained their values between forms.

The Global and WebConfig files are virtually identical between applications.

This indicates to me that the problem is somewhere within my application but
I don't know where to start looking from here.

Any suggestions?

Thank YouWe had the same sort of problem here. It took the better part of a week and
another consultant to help out before we finally gave up and just decided
that .NET has real problems with Sessions.

Our solution eventually was to try commenting out different parts of the
code that was being run before the Response.Redirect. We narrowed the bug
down to a Directory.Move command - which really didn't make any sense to us,
but anyway. A Directory.Move just basically renames a directory on the
server's file system, so we tried instead to create a new directory with the
new name, copy the contents of the old directory over, then delete the old
directory (three lines of code instead of one). And Voila! Session keeps
it's state...

"Jonk Eidersteldvr" <hydraline@.cairns.net.au> wrote in message
news:3f4eab09_2@.news.brisbane.pipenetworks.com...
> Hi,
> I am using a web application -asp, ado, C#, using CodeBehind files etc..
> I am using "InProc" session state and find that session variables are
> loosing their values between one web form and the next. I have used
"InProc"
> on my development machine and the session variable values are being
> maintained between pages.
> I copied two of the relevant forms into another application and using
> "InProc" session state they maintained their values between forms.
> The Global and WebConfig files are virtually identical between
applications.
> This indicates to me that the problem is somewhere within my application
but
> I don't know where to start looking from here.
> Any suggestions?
> Thank You
>