Link to home
Start Free TrialLog in
Avatar of Wayne Atherton
Wayne Atherton

asked on

Have a login control on the same Default.aspx page

Hi there,

i have a separate login page, which is working fine - When a user first visits my site, the Default.aspx is the home page, if the user isn't authenticated, then they are redirected to the login page, being redirected back to the Default.aspx page, when successfully authenticated.

I need to bring the login control into the Default.aspx page and make use of ASP:PAnel controls to hide certain portions of the page if the user isn't authenticated.

How do i configure the Web.Config file to do this?
Avatar of Wayne Atherton
Wayne Atherton


wakey wakey.....

Checking the login session and redirecting to login page is much simple to do.

in Default.aspx:

check the logged in user session variable e.g., session("UserName") which will be set in log in page. If the session("UserName") has value then you staty in Default.aspx else redirect it to login page.

in login page:

you can have a session variable e.g., session("UserName") to store successful logged in user details. on successful login you can store the username in the session. And then redirect to Default.aspx page. This will work.

And as you stated, you want to place the login control in the default page if the user has not authenticated. if so then why dont you add  a panel in default page and do the exact coding in the login control.

or else create the login page coding as a user control and make use of it wherever needed.
There needs to be only one page - Default.aspx.

In code behind I want to check User.Identity.IsAuthenticated. If true then hide the login panel and display main content. If false reverse panels, hiding the main content and displaying the login panel.

The method you've just posted is the traditional two page login that I'm not looking for.
Avatar of Stephan
An addition to srosebabu's comment;
If you use formsauthentication you can check with "HttpContext.Current.User.Identity.IsAuthenticated"
Thanks Stephane, but this isn't what I was looking for. Read my last response.
A bit too late with my post.

As you are saying you do a authentication check. What do you really want and why, because the post you just done gives what you need.
If you want to hide man conten you can just wrap it with a placeholder, or maybe change masterpage in pageinit?
I still need to retain forms authentication, using the conventional web.config settings. However, when I set the login page to be Default.aspx the code behind works, but I get weird behaviour with both Update Panel and ScriptManager objects. Placing a breakpoint on Page Load in Visual Studio and walking through the identity check works fine, but Visual Studio then displays another tab stating that it can't find UpdatePanel.cs - commenting out my Update panel (which is part if the main part of the page) and running again, then the ScriptManager on my page does the same thing.
Not using master pages.
How is the page set up? You say you use UpdatePanels?

Could you give me a markup code?
User generated imageUser generated image
the second image is how i'm implementing the UpdatePanel and the ScriptManager.

and the first is what happens in Visual Studio:
Avatar of Wayne Atherton
Wayne Atherton

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Answered my own question