RSS Forums RSS

how to get network login user name

Reply
Posts: 11
Reputation: anitha2324 is an unknown quantity at this point 
Solved Threads: 0
anitha2324 anitha2324 is offline Offline
Newbie Poster

Question how to get network login user name

  #1  
Mar 19th, 2007
am trying to create a web page to be used by my network users (inside my intranet)

I want to get the visitor's name of my page ( in another words to get the network login user name of the person who is visiting my web page)

i tried to use the following code but am getting error

<%
' Use the Page.User property to access authentication and
' identity information for the current user. If the user is
' not authenticated, redirect them to a login page.
Sub Page_Load(sender As Object , e As EventArgs)
If User.Identity.IsAuthenticated Then
msgLabel1.Text = "Welcome, <B>" + User.Identity.Name + "</B>!"
Else
Response.Write "sorry"
End If
End Sub
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form runat="server">
<h3><asp:label id="msgLabel1" runat="server" /></h3>
</form>
</body>
</html>


but am getting the following error



Server Error in '/' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30289: Statement cannot appear within a method body. End of method assumed.
Source Error:

Line 3: ' identity information for the current user. If the user is
Line 4: ' not authenticated, redirect them to a login page.
Line 5: Sub Page_Load(sender As Object , e As EventArgs)
Line 6: If User.Identity.IsAuthenticated Then
Line 7: msgLabel1.Text = "Welcome, <B>" + User.Identity.Name + "</B>!"

Source File: c:\inetpub\wwwroot\f\username.aspx Line: 5

Show Detailed Compiler Output:

C:\WINDOWS\system32> "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vbc.exe" /t:library /utf8output /R:"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /out:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\26676eb7\92c7e946\App_Web_szxvhp9l.dll" /debug- /win32resource:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\26676eb7\92c7e946\szxvhp9l.res" /define:_MYTYPE=\"Web\" /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Specialized,System.Configuration,System.Text,System.Text.RegularExpressions,System.Web,System.Web.Caching,System.Web.SessionState,System.Web.Security,System.Web.Profile,System.Web.UI,System.Web.UI.WebControls,System.Web.UI.WebControls.WebParts,System.Web.UI.HtmlControls "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\26676eb7\92c7e946\App_Web_szxvhp9l.0.vb" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\26676eb7\92c7e946\App_Web_szxvhp9l.1.vb"

Microsoft (R) Visual Basic Compiler version 8.0.50727.42
for Microsoft (R) .NET Framework version 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\26676eb7\92c7e946\App_Web_szxvhp9l.0.vb(101) : error BC30035: Syntax error.
Me.WriteUTF8ResourceString(__w, 0, 327, true)
~~
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\26676eb7\92c7e946\App_Web_szxvhp9l.0.vb(102) : error BC30429: 'End Sub' must be preceded by a matching 'Sub'.
End Sub
~~~~~~~
c:\inetpub\wwwroot\f\username.aspx(5) : error BC30289: Statement cannot appear within a method body. End of method assumed.
Sub Page_Load(sender As Object , e As EventArgs)
~~~
c:\inetpub\wwwroot\f\username.aspx(7) : error BC30451: Name 'msgLabel1' is not declared.
msgLabel1.Text = "Welcome, <B>" + User.Identity.Name + "</B>!"
~~~~~~~~~



--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
AddThis Social Bookmark Button
Reply With Quote  
Posts: 6
Reputation: gpm1982 is an unknown quantity at this point 
Solved Threads: 1
gpm1982 gpm1982 is offline Offline
Newbie Poster

Re: how to get network login user name

  #2  
Feb 11th, 2008
Here's the fix:

instead of the normal <% %> thing, switch to <script runat="server"></script>
Now that should solve the problem.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the ASP.NET Forum
Views: 14366 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:57 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC