Wrox Programmer Forums
|
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution 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
 
Old November 4th, 2004, 04:07 PM
Authorized User
 
Join Date: Oct 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default LONGIN: IsAuthenticated

if (Context.User.Identity.IsAuthenticated)
            {

                Greeting.Text += "<b>" + Context.User.Identity.Name + "</b>";
                UserLink.Text = "My Account";
                UserLink.NavigateUrl = "/ThePhile/Modules/Users/MyAccount.aspx";
                SignOut.Visible = true;
            }
            else
            {
                Greeting.Text += "Guest User.";
                UserLink.Text = "Click to Login";
                UserLink.NavigateUrl = "/ThePhile/Modules/Users/Login.aspx";
                SignOut.Visible = false;
            }

In my header.aspx.cs file I have the above code.

From login page when i log in or create new user it takes me back to
default.aspx page but the header
do not change to the user name.

It still says Welcome Guest User and login in link. which tells me it didn't go to the Isauthenticate argument part.

I checked the cookie and it was set on the usermachine.

after logging in if i try to go to MyAccount.aspx (by manual url typing) it throws a cast error.

I know it has been discussed many times here and i follwod all the suggestions with no luck. Help please

 
Old November 4th, 2004, 04:11 PM
Authorized User
 
Join Date: Mar 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

just a question, (i am not c# guru), why are you using += to assign the label value to your context.user??

I dont think the problem is here, you need to post the error and also the code for your login.

Rob

 
Old November 4th, 2004, 04:51 PM
Authorized User
 
Join Date: Oct 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The reason += is there cause on lablel Greeting it adds "Welcome"
then plus Guest user or the username for a personalized greeting

I don't get a error on login.aspx or new.aspx after i login or add user it takes me to the default.aspx but the header information about the user name and logout button don't show up.

when i type MyAccount.aspx in the URL after login I get this error.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:


Line 90: }
Line 91: }
Line 92: if ( ((PhilePrincipal)Context.User).Roles.Count > 0 )
Line 93: {
Line 94: RoleList.Visible = true;


Source File: c:\wrox\thephile\modules\users\myaccount.aspx.cs Line: 92


 
Old November 4th, 2004, 04:56 PM
Authorized User
 
Join Date: Mar 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry about the +=, c# confuses me. You could try and comment out the section From line 92 intill that code segment ends and see if that part of the code is calling the problem. I had loads of these when i first started using .Net, its a trial and error situation, you have to ensure that you are casting the correct type.

In Vb its

CType(Context.User, PhilePrinciple)

sorry if i am not being any help.

Rob

 
Old November 4th, 2004, 05:33 PM
Authorized User
 
Join Date: Oct 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i did comment it out now i can go to the page but only the header and footer shows up but not the form to edit.

appreciate u taking the time to help.

 
Old November 4th, 2004, 06:26 PM
Authorized User
 
Join Date: Mar 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could you post the code for the whole page? the cast exception seems to be with the line if ( ((PhilePrincipal)Context.User).Roles.Count > 0 ), i am not sure how you cast in c#, this is the line you need to work on.

Rob

 
Old November 5th, 2004, 12:28 PM
Authorized User
 
Join Date: Oct 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

LOGIN.ASPX.CS
================================================== ====================
public class Login : Wrox.ThePhile.Web.PhilePage
    {
        protected System.Web.UI.WebControls.TextBox EmailAddress;

        protected System.Web.UI.WebControls.TextBox Password;
        protected System.Web.UI.WebControls.Button Submit;
        protected System.Web.UI.WebControls.RequiredFieldValidator EmailValidator;
        protected System.Web.UI.WebControls.ValidationSummary ValidatorSummary;
        protected System.Web.UI.WebControls.Label LoginResult;
        protected System.Web.UI.HtmlControls.HtmlForm Default;
        protected System.Web.UI.WebControls.Label AuthRedirectFailure;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            if ((Request["ShowError"] == "true") || (Request["ShowError"] == "1"))
            {
                AuthRedirectFailure.Text = "You did not have sufficient permission to view the previous page. Please login below.";
                AuthRedirectFailure.Visible = true;
            }
            else
            {
                AuthRedirectFailure.Visible = false;
            }
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            base.OnInit(e);
            InitializeComponent();
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Submit.Click += new System.EventHandler(this.Submit_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void Submit_Click(object sender, System.EventArgs e)
        {
            PhilePrincipal newUser = PhilePrincipal.ValidateLogin( EmailAddress.Text, Password.Text );
            if (newUser == null)
            {
                LoginResult.Text = "Login failed for" + EmailAddress.Text;
                LoginResult.Visible = true;
            }
            else
            {
                Context.User = newUser;
                FormsAuthentication.SetAuthCookie( EmailAddress.Text, true );

                Response.Redirect("/ThePhile/default.aspx");
            }
        }

        private void Register_Click(object sender, System.EventArgs e)
        {
            Response.Redirect("new.aspx");
        }
    }
}
================================================== =================

I can see lots of posting on this topic and i followed everthing but still no luck.

My problem is after login it redirects me to the default page but the
header will not show the user name logout and account setting links.

I would really really appreciate if some one helps. thanks

 
Old November 6th, 2004, 06:37 AM
Registered User
 
Join Date: Nov 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi.

It looks like you did not replace the default Context.User with an instance of PhilePrincipal.

Try creating an instance of PhilePrincial!

sam

 
Old November 6th, 2004, 05:05 PM
Authorized User
 
Join Date: Oct 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

but i thought philebase does that. I could be wrong. i will try it. thanks.

 
Old November 7th, 2004, 09:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, the base class does this if you have it set up right. This is clearly where your problem is, but it's hard for me to debug it without looking at it myself.

Maybe this is not true:

if (Context.User.Identity.IsAuthenticated)

Or maybe this is failing somehow:

PhilePrincipal newUser = new PhilePrincipal( Context.User.Identity.Name );

Eric









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