Re: How to pass in username as query parameter?



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

.



Relevant Pages

  • Re: How to pass username in the login control to next page?
    ... would access their username through their authentication typically. ... I have VB 2005, I use login control to logn in, after log in, I go to ... Protected Sub Login1_Authenticate1(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: How to pass username in the login control to next page?
    ... access their username through their authentication typically. ... I have VB 2005, I use login control to logn in, after log in, I go to ... Protected Sub Login1_Authenticate1(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • A simple Login Application using VS2005 Visual Web Express
    ... I wanted to develop a very simple login application by using VS 2005 Visual Web Express. ... LoginStatus1 control ... If user is admin, load the page called demo and display everything on this page ... Protected Sub Login1_LoggedInHandles Login1.LoggedIn ...
    (microsoft.public.dotnet.framework.aspnet)
  • User.Identity.IsAuthenticated return true
    ... I have a webcrontrol from login: ... Protected Sub Login1_LoggedIn(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.aspnet)
  • How to pass username in the login control to next page?
    ... I have VB 2005, I use login control to logn in, after log in, I go to ... I want to use the login username in another, ... Protected Sub Login1_Authenticate1(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.aspnet.security)