944,168 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 32983
  • ASP.NET RSS
Mar 19th, 2007
0

how to get network login user name

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
anitha2324 is offline Offline
11 posts
since Mar 2007
Feb 11th, 2008
0

Re: how to get network login user name

Here's the fix:

instead of the normal <% %> thing, switch to <script runat="server"></script>
Now that should solve the problem.
Reputation Points: 12
Solved Threads: 1
Newbie Poster
gpm1982 is offline Offline
6 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: How to Make a mailbox with all the functionss!!!!
Next Thread in ASP.NET Forum Timeline: oracle database





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC