Re: How to pass in username as query parameter?
- From: HomerS007@xxxxxxxxx
- Date: Mon, 02 Jul 2007 07:52:17 -0700
On Jul 2, 12:15 am, "Riki" <r...@xxxxxxxxxxxxx> wrote:
HomerS...@xxxxxxxxx wrote:
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.
--
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
.
- References:
- How to pass in username as query parameter?
- From: HomerS007
- Re: How to pass in username as query parameter?
- From: Riki
- How to pass in username as query parameter?
- Prev by Date: Re: Create Database
- Next by Date: Re: Create Database
- Previous by thread: Re: How to pass in username as query parameter?
- Next by thread: Display Total in Grid View
- Index(es):
Relevant Pages
|
|