How to pass in username as query parameter?

H

HomerS007

Hi,

I'm using asp.net 2.0 and sql server 2000 for my first ever project.
On one of the page in the application, I want to limit what the user
can see based on his/her login. It's a page that has sensitive
personal info like social security number and I only want user to see
their own information and no one else. Can anybody please tell me how
to pass in the username as a query parameter? I used a DetailsView
control to and configure the sqlDataSource's Select statement to
SELECT ... FROM ... WHERE username = @username. For the @username
parameter, I need to pass in the username of the login user. Can
somebody please help me?

Thanks,
Jon
 
M

Masudur

Hi,

I'm using asp.net 2.0 and sql server 2000 for my first ever project.
On one of the page in the application, I want to limit what the user
can see based on his/her login. It's a page that has sensitive
personal info like social security number and I only want user to see
their own information and no one else. Can anybody please tell me how
to pass in the username as a query parameter? I used a DetailsView
control to and configure the sqlDataSource's Select statement to
SELECT ... FROM ... WHERE username = @username. For the @username
parameter, I need to pass in the username of the login user. Can
somebody please help me?

Thanks,
Jon

Hi.. jon...

you can accomplish this job in various way...
you can keep the user name in session and then configure datasourse
set the where clause and user session to set the value... or you can
take the value from provide...
or perhaps you can set things manually
string Username = Page.User.Identity.Name;
SqlDataSource2.SelectParameters.Clear();
SqlDataSource2.SelectParameters.Add("username", Username );

just like that.......

Thanks
Masudur
www.kaz.com.bd
http://munnacs.110mb.com
 
R

Riki

Hi,

I'm using asp.net 2.0 and sql server 2000 for my first ever project.
On one of the page in the application, I want to limit what the user
can see based on his/her login. It's a page that has sensitive
personal info like social security number and I only want user to see
their own information and no one else. Can anybody please tell me how
to pass in the username as a query parameter? I used a DetailsView
control to and configure the sqlDataSource's Select statement to
SELECT ... FROM ... WHERE username = @username. For the @username
parameter, I need to pass in the username of the login user. Can
somebody please help me?

Thanks,
Jon

For my own convenience, I created a user control for this purpose (in
VB.NET):

<%@ Control Language="VB" ClassName="UserName" %>

<script runat="server">
Public ReadOnly Property UserName() As String
Get
Return lblUserName.Text)
End Get
End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If (Not IsPostBack) Then
lblUserName.Text = Page.User.Identity.Name
End If
End Sub

</script>
<asp:Label runat="server" ID="lblUserName" Visible="false"></asp:Label>

Drop it on your page, and connect the datasource parameter to it.
 
H

HomerS007

For my own convenience, I created a user control for this purpose (in
VB.NET):

<%@ Control Language="VB" ClassName="UserName" %>

<script runat="server">
Public ReadOnly Property UserName() As String
Get
Return lblUserName.Text)
End Get
End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If (Not IsPostBack) Then
lblUserName.Text = Page.User.Identity.Name
End If
End Sub

</script>
<asp:Label runat="server" ID="lblUserName" Visible="false"></asp:Label>

Drop it on your page, and connect the datasource parameter to it.

--

Riki- Hide quoted text -

- Show quoted text -

Hello all,

I stayed up into the wee hour of the night last night tripping on this
problem. I finally found a solution from http://aspnet.4guysfromrolla.com/articles/112206-1.aspx.
In addition to the query parameter I set up in the datasource, all I
have to do is to create an event handler for the datasource's
Selecting event.

Protected Sub SqlDataSource1_Selecting(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)
Handles SqlDataSource1.Selecting
e.Command.Parameters("@EmployeeID").Value = User.Identity.Name
End Sub

I'm new to ASP.NET and I'm sure to run into lots and lots of
problems. Thank you Masudur and Riki for your help.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top