User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 423,539 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,235 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 2979 | Replies: 9
Reply
Join Date: Nov 2007
Posts: 18
Reputation: AniWeb is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
AniWeb AniWeb is offline Offline
Newbie Poster

Session variable keeping login information

  #1  
Dec 15th, 2007
hi all,

I have to maintain a Session variable in the Login page, which is used to keep login information for user.

It is not required for user to go for login and access all pages. I mean that if user has an account then he/she can get login otherwise it is not necessary to go for login, they still can access all pages.

I store "no" string in the session variable in the login page, if user does not get logged.

The problem is that when I want to retrieve string from this variable in other pages, and user did not get logged, then I always get error that 'Session variable is not created'. How I can solve this problem?

Please reply as soon as possible.

Thanks.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2007
Posts: 257
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: Session variable keeping login information

  #2  
Dec 17th, 2007
Can u provide code for u r problem,it will be more easy to understand u r query.
Reply With Quote  
Join Date: Nov 2007
Posts: 18
Reputation: AniWeb is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
AniWeb AniWeb is offline Offline
Newbie Poster

Re: Session variable keeping login information

  #3  
Dec 17th, 2007
In the Login Page I have done:-

protected void Page_Load(object sender, EventArgs e)
    {
        Session["login"] = "no";
    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        if (myObj.UserLogin(Login1.UserName, Login1.Password) == "exists")
        {
            Response.Redirect("HomePage.aspx");
            Session["login"] = Login1.UserName;
        }
        else
            Response.Write("Please verify UserName or Password");           
    }

And tried to get Sessin value in other pages.
by:- string s=Session["login"].ToString();

but I get error that Session variable is not created.
Reply With Quote  
Join Date: Apr 2007
Posts: 257
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: Session variable keeping login information

  #4  
Dec 18th, 2007
HI,
I have a doubt here,how the application knows whether the user has account or not,i guess from your code here that,u r using login page to enter that info.when r u getting the error session variable not created,when the user has logged in with the existing username or password.
Reply With Quote  
Join Date: Apr 2007
Posts: 257
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: Session variable keeping login information

  #5  
Dec 18th, 2007
Hi,
I think i found u r answer,u are redirecting the page even before the session variable is created. so place the session first and then redirect the page.
Reply With Quote  
Join Date: Nov 2007
Posts: 18
Reputation: AniWeb is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
AniWeb AniWeb is offline Offline
Newbie Poster

Re: Session variable keeping login information

  #6  
Dec 18th, 2007
hi

thanks for giving time in my problem.

Actually my problem is that how I can maintain login information accessiable in all the pages of the website.

Is there any other solution for it rather then using Session variable.

If I use Session variable in login page, then if user access other page of the website directly then there error will be occure that Session variable is not created.

Please solve my problem, I got tired with this work.

thanks
Reply With Quote  
Join Date: Apr 2007
Posts: 257
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: Session variable keeping login information

  #7  
Dec 24th, 2007
I guess cookies can solve u r problem but i have no idea on using cookies in my application,search msdn for further info.hope it works for u
Reply With Quote  
Join Date: Dec 2007
Posts: 287
Reputation: ericstenson is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 28
Colleague
ericstenson's Avatar
ericstenson ericstenson is offline Offline
Posting Whiz in Training

Re: Session variable keeping login information

  #8  
Dec 25th, 2007
Hi, I have found the best way to pass user information between pages is with Server.Transfer("~/page.aspx", true)

what you do is first create the string you want to pass between pages

ON SOME MOUSE CLICK OR EVENT:

dim isvalidated as string
dim username as string
isvalidated = "Yes"
username = "eric"

context.items.add("isvalid", isvalidated)
context.items.add("usern", username)
server.transfer("~/page.aspx", true)

---

once it goes to the new page you can "retrieve" these values

dim isvalid as string
dim usern as string


ON PAGELOAD FOR NEXT PAGE
isvalid = context.items("isvalid")
usern = context.items("usern")

what i usually do is validate at this point...

if isvalid = "" then
server.transfer("~/notauthorized.aspx")
else

DO WHATEVER YOU WANT

...

end if
Reply With Quote  
Join Date: Oct 2005
Posts: 54
Reputation: benyam_dessu is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
benyam_dessu benyam_dessu is offline Offline
Junior Poster in Training

Re: Session variable keeping login information

  #9  
Dec 26th, 2007
Dear Colleagues:

I want to separate interface design from its code (in my asp.net school project). So that , I'm trying to use a code-behind using vb.net. For example in my login page I provide the user with username and password input, then handle the user input from lgoin.vb file. But I don't know how to get the values of textbox that are placed in login.aspx file.

How Can access these username and password textbox values in the login.vb code to check the user input. To give u some idea about my code, just see the following simple code:

************************
login.aspx
************************

<%@ page Inherits ="class1" scf="lgoin.vb"%>

<html>
<head></head>
<body>
<form id="form1" runat="server">

<asp:TextBox ID="txtuname" runat="server"/>
<asp:TextBox ID="txtpass" runat="server"/>
<asp:Button ID="btnlog" runat="server" Text="Button" OnClick ="button_click" />
</form>
</body>
</html>
************************
login.vb
************************
Imports Microsoft.VisualBasic
Imports system.Web
Imports system.Web.UI
Imports system.Web.UI.Control
Imports system.Web.UI.HtmlControls

Public Class Class1
Inherits Page

Sub button_click(ByVal s As Object, ByVal e As EventArgs)
'based on the the user input(username and passward)
' I want to redirect the users to different pages
' if txtpass.text= "x" and txtuname="something" then

'Response.Redirect("x.aspx")
'else
'Response.Redirect("y.aspx")
End Sub
End Class
************************
As u have seen from the code I commented some lines on login.vb file. This is because I can't access the txtuname and txtpass textboxes from lgoin.vb.


Please help me how can I do that


Regards,

Ben
Reply With Quote  
Join Date: Dec 2007
Posts: 1
Reputation: seth_kaufmann is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
seth_kaufmann seth_kaufmann is offline Offline
Newbie Poster

Re: Session variable keeping login information

  #10  
Dec 27th, 2007
This depends on a lot of things. How are you validating users in the first place? Using a database, using the web.config file? If you are using a database, it would be something like the following:

Dim Myconn As SqlConnection = New SqlConnection("server=localhost; database=dbaseName; Trusted_Connection=Yes")
Dim DBselect As String
DBselect = "select whatever from table_namewhere some condition"
Dim Mycommand As SqlCommand = New SqlCommand(DBselect, Myconn)
'Feed Parameter to database get the access level
Mycommand.Parameters.Add("@param", SqlDbType.VarChar).Value = txtUName.value
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 5:39 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC