0

I'm working on a school project (so security isn't an issue) that requires me to get the name of the currently logged in user (to use as an argument for an SQL query for a datagrid)

Since the SQL query for the datagrid binding is stored in the aspx file, I can't use User.Identity.Name.ToString() like I would if this were in my c# file.

I am using the Microsoft authentication system that comes pre-built in visual studio asp.net webforms

शेखर
  • 17,412
  • 13
  • 61
  • 117

2 Answers2

0

You can use filter parameter of SQL Data-source.

Try using plain parameter (asp:Parameter). Yet another alternative is using SessionParameter or writing your own custom parameter (see this SO question: How to utilize ASP.NET current user name in SqlParameter without code-behind)

Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117
0

You should be able to use the following in the ASPX file:

 <%=HttpContext.Current.User.Identity.Name %>

You obviously won't need the tags if you are plugging it into an existing code block...

JP.
  • 5,536
  • 7
  • 58
  • 100