Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 10th, 2003, 04:53 AM
Registered User
 
Join Date: Jun 2003
Location: London, , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default ascx issue with User.Identity.Name

Hi,

can anyone help with the following...

I have 2 pages (login.aspx and accschk.aspx) and they work fine.

accschk.aspx
---------------
<%@ Page Language="VB" %>
<script runat="server">

    ' Insert page code here
    '
    Sub Page_Load(Src As Object, E As EventArgs)
        Response.Write (User.Identity.Name & "<br />")
    End Sub

</script>
<html>
    <head>
    </head>
    <body>
        <form runat="server">

        </form>
    </body>
</html>

i.e. when run the user enters his login name, and then accschk.aspx displays the login name. It works ok.

I then decided to incorporate the above into an ascx, and changed the code as follows...

accschk.ascx
---------------
<%@ Control Language="VB" %>
<script runat="server">

    ' Insert user control code here
    '
    Sub Page_Load(Src As Object, E As EventArgs)
        Response.Write (User.Identity.Name & "<br />")
    End Sub

</script>


accschk.aspx
---------------
<%@ Page Language="VB" %>
<%@ Register TagPrefix="uc0" TagName="haccschk" Src="accschk.ascx" %>
<script runat="server">

    ' Insert page code here
    '

</script>
<html>
    <head>
    </head>
    <body>
        <form runat="server">

        </form>
    </body>
</html>

Now I get an error in the ascx file.

Error
------
Compiler Error Message: BC30451: Name 'User' is not declared.

Source Error:



Line 6: '
Line 7: Sub Page_Load(Src As Object, E As EventArgs)
Line 8: Response.Write (User.Identity.Name & "<br />")
Line 9: End Sub
Line 10:

Can anyone help?


Rgds Ian
  #2 (permalink)  
Old June 10th, 2003, 11:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Wien, Wien, Austria.
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

Ian,

In the .ascx file you have to replace User.Identity.Name statement with HttpContext.Current.User.Identity.Name

Regards,
NotNowJohn

...but the Soon is eclipsed by the Moon
  #3 (permalink)  
Old June 11th, 2003, 02:50 AM
Registered User
 
Join Date: Jun 2003
Location: London, , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I discovered the solution myself. It is...

Context.User.Identity.Name


Rgds Ian


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with RssReader.ascx user control retroviz BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 October 24th, 2007 07:06 PM
Identity Property issue Navy1991 SQL Server 2000 2 January 6th, 2006 05:27 AM
Context.User in siteheader.ascx.cs scottf BOOK: ASP.NET Website Programming Problem-Design-Solution 7 November 3rd, 2005 12:52 PM
Identity Column Issue mepancha SQL Server 2000 5 June 17th, 2005 03:00 PM
Include vs. User control(ascx) ajindal General .NET 4 January 8th, 2005 09:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.