Last post May 27, 2008 12:33 PM by DotNetAdvisor
Apr 02, 2008 11:42 AM|misbahmurtza|LINK
Hello nice people,
I am working on a web application with an access database. i have recently created a asp.net login control for my login page which means that i set my users up using the asp.net configuration. i have the users course and study details in a access database
and was wondering if i could display them details on the web page ONLY for that current user who logged in. i used asp.net login control as it is much easier but now i am having problems with linking the user login and my data in the access database. i have
used the 'login name' control to display the users 'student ID' which is used to login. The control's misc 'ID' is 'StudentID' and i have created a gridview that should display data for the current user, which is bounded to the access database. for the datagrid
view i set the 'datakeynames' to 'StudentID'. I want to link the gridview with the 'login name' control so that the 'login name' is the parameter for the gridview. I hope i make sense. If any1 thinks that i should create my own login page rather than usinng
asp.net login control, then tell me. i am using VB in asp.net for my web application. Please help, i have a deadline coming soon.
Apr 02, 2008 02:52 PM|DotNetAdvisor|LINK
Hey you won't need to create a login control.
What it sounds like you need to do is just access the username of the current user and use that for filtering the data. If so you can retrieve the username from this property:
May 22, 2008 07:20 AM|misbahmurtza|LINK
i tried pasting the httpcontext.current.user.identity.name as shown above but its asking me to declare 'httpcontext' but i dnt knw why. where am i supposed to be inserting this code in my application? i tried inserting in the page load of the page i want
to display the student details. i am not going to use the loginName control because it does not allow me to filter data. if so i donjt know how to.
please can u urgently help me. i am using vb in asp.net could you tell me clearly where i need to insert the above code and if i need to declare then what should i delcare it as. will i be able to display the user on a label? please help i am desperate.
May 22, 2008 07:46 AM|DotNetAdvisor|LINK
That line of code requires that you import the System.Web namespace in whatever class you're using.
Where you would use this line is wherever you're setting up your query for querying your access database. Are you using an AccessDataSource, SqlDataSource or are you setting it up in code yourself?
May 22, 2008 07:54 AM|misbahmurtza|LINK
i will be using accessdatasource if that does not work then i will have to set it up myself in code. i will now try to import the system.web namespace where i want to display the users details.
May 22, 2008 08:04 AM|misbahmurtza|LINK
the 'HttpContext' is underlined and says that it needs to be declared see below my code.
May 22, 2008 09:10 AM|DotNetAdvisor|LINK
Let's get back to what you're trying to accomplish. The line of code I gave you can't just be put somewhere and do something on its own. It gives you the username for the currently logged in user. So you use that wherever you're setting the value of your
If you're going to use an AccessDataSource you'll need to setup a SelectParameter for the username. Then setup a handler for the OnSelecting event. Something like this:
Protected Sub DataSource_Selecting(sender as Object, e as SqlDataSourceSelectingEventArgs)
e.Command.Parameters("@UserName").Value = HttpContext.Current.User.Identity.Name
This code assumes that you've setup a parameter in your query called @UserName.
May 22, 2008 09:57 AM|misbahmurtza|LINK
can i display the user using that code
May 23, 2008 10:10 AM|DotNetAdvisor|LINK
can i display the user using that code
Yes, you could setup a label or literal in your page and in the Page_Load handler set the control's Text property to the value of that line.
May 25, 2008 05:50 PM|misbahmurtza|LINK
as you have probably noticed that i am not so good with vb code so if possible could you help me with the vb code needed to display the user on the label on page load event and to set the controls text property to the value of the line above. sorry for all
May 25, 2008 09:26 PM|DotNetAdvisor|LINK
It would look like this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
LabelID.Text = HttpContext.Current.User.Identity.Name
Be sure to replace "LabelID" with the actual ID of the label whose text you want to set.
May 27, 2008 09:20 AM|misbahmurtza|LINK
i would like to say thank you for your help with this problem. i have sucessfully solved the problem with all your help. sorry for all that. i have learnt so much from this.
May 27, 2008 12:33 PM|DotNetAdvisor|LINK
You're welcome! Glad I could help.