Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Context.User.Identity.Name Empty

Status
Not open for further replies.

ArmenD

Programmer
Feb 3, 2005
101
US
hi,
don't know why Context.User.Identity.Name is coming out Empty? any suggestions

Code:
<%@ Page language="VB" %>
<html>
<head>
<title>Forms Authentication</title>

<script runat=server>
   Sub Page_Load ( Src As Object, E As EventArgs )
      Welcome.InnerHtml = "Hello, " + Context.User.Identity.Name
   End Sub
   Sub Signout_Click ( sender As Object, E As EventArgs )
      FormsAuthentication.SignOut ( )
      Response.Redirect ( "Login.aspx" )
   End Sub
</script>

<body>
<h3>Using Forms Authentication</h3>
<span id="Welcome" runat=server/>
<form runat=server>
   <p><input type="submit" onServerClick="Signout_Click" Value="Signout" 
      runat="server"/>
</form>
</body>
</html>
 
Hi,

How are you assigning this value from your login page?

J

----------------------------------------------------------------------------------------
Try saying Tek-Tips Tek-Tips Tek-Tips more than 3 times in a row....no chance!
 
How are you assigning this value from your login page?
would you please give me an example of how to set it?
 
i read the text, so is Context.User.Identity.Name automatically directed by the os thru the browser?

it's just that i am trying to authenticate using database, so I am not quite sure who assigns Context.User.Identity.Name a value?

i think the example posted was authenticating via file since small # of allowed users.

 
Hi,

When your users login and you authenticate them by checking that their username and password matches, you can then call

FormsAuthentication.RedirectFromLoginPage(txtUsername, ChkPersist.Checked)

Where txtUsername is the id of your text box that accepts the username.

ChkPersist is the id of a checkbox if you want to set a persistant cookie (if not use "false")

Now you can retrieve the username by using

Label1.Text = HttpContext.Current.User.Identity.Name

Your web config file must also have

<authentication mode="Forms">
<forms name=".ASPXAuth" loginUrl="Login.aspx" protection="All" timeout="60" />
</authentication>

(change the LoginUrl to your own)

Hth

J



----------------------------------------------------------------------------------------
Try saying Tek-Tips Tek-Tips Tek-Tips more than 3 times in a row....no chance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top