Login control FAQ :

This post contains some of the most asked questions when using login control.

1- how to redirect users to different pages based on their roles.

This can be done by handling the LoggedIn event of the Login control. 

protected void Login1_LoggedIn(object sender, EventArgs e)    {
// if there is no returnUrl in the query string , we redirect based on user role
if (string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
{
// please don't use User.IsInRole here , because it will not be populated yet at this stage.
if (Roles.IsUserInRole(Login1.UserName, "Admins"))
Response.Redirect("~/Admins/Default.aspx");
else if (Roles.IsUserInRole(Login1.UserName, "Editors"))
Response.Redirect("~/Editors/Default.aspx");
}
}
2- how to hide the login control from the logged in users ?

To hide the login control for the logged in users , set it’s VisibleWhenLoggedIn property to false.

<asp:Login ID="Login1" runat="server" VisibleWhenLoggedIn="False" …

You can also use the LoginView control to accomplish that :

    <asp:LoginView ID="LoginView1" runat="server">
<AnonymousTemplate>
<asp:Login ID="Login1" runat="server">
</asp:Login>
</AnonymousTemplate>
</asp:LoginView>
 
3-How to hide “remember me next time” checkbox ?

You may need to prevent the users from checking “remember me next time” checkbox to prevent crating a persistent authentication cookie.

To do that , you just need to set it’s DisplayRememberMe property to “false” and then you need to set it’s RememberMeSet property.

If you want to force the website to remember the users , you set the RememberMeSet property to true, else you set it to false.

<asp:Login ID="Login1" runat="server" DisplayRememberMe="false" RememberMeSet="false" …


4-How to use the login control with my existing users table ?

By default,Login control will use the membership provider to validate users credentials , but if you already have your custom users table , you can use the login control like this :

protected void  Login1_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e)
{
string userName = Login1.UserName;
string password = Login1.Password;

bool result = UserLogin(userName, password);
if ((result))
{
e.Authenticated = true;
}
else
{
e.Authenticated = false;
}
}

private bool UserLogin(string userName, string password)
{

// read the coonection string from web.config
string conString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;

using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conString))
{
//' declare the command that will be used to execute the select statement
SqlCommand com = new SqlCommand("SELECT UserName FROM Users WHERE UserName = @UserName AND Password = @Password", con);

// set the username and password parameters
com.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = userName;
com.Parameters.Add("@Password", SqlDbType.NVarChar).Value = password;

//' execute the select command
try
{
con.Open();
//' execute the select statment
string result =Convert.ToString( com.ExecuteScalar());
//' check the result
if (string.IsNullOrEmpty(result))
{
//invalid user/password , return flase
return false;
}
else
{
// else return true , valid login
return true;
}
}
catch (Exception ex)
{
throw;
}
}
}
  

5-I don’t want the login control to render as html table , instead i want it to render as div , how to do that ?

You can use the CSS friendly control adapters , check this link.


6- I’m getting invalid login after i published my website , the user name and password was working locally , what’s the problem ?

One possible reason is the applicationName in membership configuration, check this link for more information .

7-After i published my website , I’m getting System.Web.Security.SqlMembershipProvider' requires a database schema compatible with schema version '1'  .. error ,what to do ?

One possible reason is that the published version of  "aspnet_SchemaVersions" table doesn't have the correct values , please make sure that it have the values like below :

Feature CompatibleSchemaVersion 
IsCurrentVersion
common 1 TRUE
health monitoring 1 TRUE
membership 1 TRUE
personalization 1 TRUE
profile 1 TRUE
role manager 1 TRUE


8-How to display the login in popup ?

http://weblogs.asp.net/lkempe/archive/2007/01/28/login-control-in-an-asp-net-ajax-toolkit-popupcontrolextender-with-a-close-button.aspx

9- How can i log the invalid login attempts ?

You can handle the LoginError event of the login control :

    protected void Login1_LoginError(object sender, EventArgs e)
{
// here you can login the invalid attempts
string UserName = Login1.UserName;
string Password = Login1.Password;
// log the attempt

}

10-I' specified my website users in the credential section in web.config , can i still use the login control ?

Yes you can , you just need to handle the login control authenticate event .

Assume you have this Credential section in web.config :

<authentication mode="Forms">
<forms>
<credentials passwordFormat="Clear">
<user name="User1" password="****" />
<user name="User2" password="****" />
</credentials>
</forms>
</authentication>

You can let the login control use the mentioned section like this :

    protected void Login1_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e)
{
string UserName = Login1.UserName;
string Password = Login1.Password;

if (FormsAuthentication.Authenticate(UserName, Password))
{
e.Authenticated = true;
}
else
{
e.Authenticated = false;
}
}

The FormsAuthentication.Authenticate method will automatically check users against the credential section.

11- I'm not using FormsAuthenticaiton, instead I'm using the session object to secure my website , can i still use the login control ?

Yes , you can use it , please read my post about this.

 

Hope it helps.


Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
3/27/2009 4:31:50 PM
asp.net.faq 380 articles. 0 followers. Follow

4 Replies
798 Views

Similar Articles

[PageSpeed] 59
Get it on Google Play
Get it on Apple App Store

 Hey,

Great tips Anas, I have learned a few things in this post!

I just wanted to add a couple of notes:

4-How to use the login control with my existing users table ?

You could also create a custom membership provider so that this works seamlessly with your login control:


5-I don’t want the login control to render as html table , instead i want it to render as div , how to do that ?

You can also take control over the markup of your Login control by clicking the smart tag (the arrow in the top right of the control when viewed in Design View) and click Convert To Template.

This will expand all the code so you can style it up however you like.

 

 

0
rtpHarry
3/27/2009 8:33:06 PM

Hi,

rtpHarry:

4-How to use the login control with my existing users table ?

You could also create a custom membership provider so that this works seamlessly with your login control:

Sure, that's another solution for working with custom tables.If you followed this way,there is no need to customize or write any code for the Login control , the control must work natively with no problems.

rtpHarry:

5-I don’t want the login control to render as html table , instead i want it to render as div , how to do that ?

You can also take control over the markup of your Login control by clicking the smart tag (the arrow in the top right of the control when viewed in Design View) and click Convert To Template.

This will expand all the code so you can style it up however you like.

The login control always create a table to wrap it's contents , so even you customized it's layout and used <div> , the control will add outer html table to the rendered markup.

Thanks


Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
3/27/2009 8:52:57 PM

anas:

rtpHarry:

5-I don’t want the login control to render as html table , instead i want it to render as div , how to do that ?

You can also take control over the markup of your Login control by clicking the smart tag (the arrow in the top right of the control when viewed in Design View) and click Convert To Template.

This will expand all the code so you can style it up however you like.

The login control always create a table to wrap it's contents , so even you customized it's layout and used <div> , the control will add outer html table to the rendered markup.



Good point!
0
rtpHarry
3/27/2009 10:16:28 PM

Hi

It's really great tips. i was searching this type of information, but now i got from this post.

Thanks


Chandra Dev
0
chandradev1
3/28/2009 4:14:29 AM
Reply:

Similar Artilces:

Net:Net:Net::LDAP::FAQ
------_=_NextPart_001_01C6429F.D89AA417 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, Net::LDAP Net::LDAPS Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, ....) password? I don't like to write the secret password to the perl file. Best regards Barbara Wilbert ------_=_NextPart_001_01C6429F.D89AA417-- Wilbert Barbara (CI/OSI) * wrote: > Hello, > > Net::LDAP > Net::LDAPS > > Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, > ......

FAQ-O-Matic for DBI FAQ(Please submit FAQs for a patch)
To make it easier to maintain while we are going through the rewrite of the DBI FAQ, I've installed and configured FAQ-O-Matic to help us through this process. I'm hoping to have the first DBI::FAQ patch in this weekend, so hopefully we can get a few (a lot:-) more FAQs in here. http://xmlproj.dyndns.org/cgi-bin/fom This will take you to the FAQ-O-Matic for DBI. You can look, play, but you'll need an email and password set up in order to insert/update stuff. For those willing to contribute, please send me your email address you'd like to use as a username and a...

[FAQ] perl5-porters FAQ
Welcome to perl5-porters! Welcome to the Perl development mailing list, perl5-porters. Whether you're here to watch the latest directions in Perl's development, or to get actively involved yourself, this FAQ will hopefully help you understand some of what goes on here. ----------------------------------------------------------------------- 1) Administration 1.1) Help! How do I unsubscribe? Send mail to <perl5-porters-unsubscribe@perl.org>, and await a response. Once you reply to the response, you'll be unsubscribed. 1.2) I'm not subscribed - how ...

.NET FAQ
Hi All, Does anyone know about a link some FAQ's for the interviews/tests in .NET. Anything in VB.NET, ASP.NET, C#, .NET Frameowrk would be appreciated. Thanks in advance, Saint. The .NET positions that I have interviewed for asked me a wide range of questions from technical knowledge to personal things. I would prepare to get to know about Object Oriented Design and Programming to the point where you can express an opinion on why you think it's better or worse. I'd also get to know n-tier programming. I've been asked about my experience in n-tier programming and what I think...

DBI-FAQ Volunteer needed to transfer old DBI::FAQ data to new FAQ
------_=_NextPart_001_01C268B8.5D67CC70 Content-Type: text/plain In search for a volunteer to transfer the answers from the old FAQ, which are not already in the new version and update the FAQ-O-Matic. If anyone is interested, please let the list know. Any help on this would be **greatly** appreciated. Ilya Sterin ------_=_NextPart_001_01C268B8.5D67CC70-- On Mon, 30 Sep 2002 13:34:17 -0600 "Sterin, Ilya" <Isterin@ciber.com> wrote: > In search for a volunteer to transfer the answers from the old FAQ, which > are not already in the new version and upda...

RE: Re: FAQ-O-Matic for DBI FAQ(Please submit FAQs for a patch)
Ah, yes. I'm confused, not enough sleep lately:-) Sorry. Still please let me know when you plan on setting up the FAQ-O-Matic. Ilya -----Original Message----- From: Scott T. Hildreth To: dbi-users@perl.org Cc: Tim.Bunce@pobox.com Sent: 4/9/02 9:32 AM Subject: FWD: Re: FAQ-O-Matic for DBI FAQ(Please submit FAQs for a patch) Ilya, I think you have me confused with this person. >Scott, thanks for the perlmonks link to db questions as I got quite a >few FAQs from there. -----FW: <1018279020.3cb1b46ca1231@webmail.med.yale.edu>----- Date: Mon, 0...

FAQ
Kindly tell the pseudocode to solve the following problem: An user input is provided to a perl program by STDIN. This input is utilised by a fortran program to perform some function. How do i connect both the programs & get the output from the fortran program to the user via the perl program itself. Waiting for an early response. thanking you... _______________________________________________________ Too much spam in your inbox? Yahoo! Mail gives you the best spam protection for FREE! http://in.mail.yahoo.com On Wed, 6 Jul 2005, madhurima das wrote: &...

FAQ
Hi, Where could I find a FAQ for S-Designor? Thanks in advance. One pretty good resource is Powersoft's web site at www.powersoft.com, under design tools tech support. There is an infobase of issues and other documents you might want to check out. For another look, check out www.aisintl.com. That should keep you busy for a while. Mike Nicewarner Marcelo S. Dias <marcelo.dias@nutecnet.com.br> wrote in article <01bc8806$58221060$5df9f8c8@dcs>... > Hi, > Where could I find a FAQ for S-Designor? > Thanks in advance. > ...

FAQ
Name: MP Email: mpierceatorschelndotcom Product: Firefox Summary: FAQ Comments: Why do the installation instructions fail to mention which Linux command is used to install? Browser Details: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031030 ...

FAQ
Why hasn't this forum got a FAQ? I think it would be a very useful addition!...

FAQ
What if we just start writing some random questions/answers into perl-date-time/web/htdocs/faq.html ? - Flavio S. Glock On Wed, 7 May 2003, Flavio S. Glock wrote: > What if we just start writing some random questions/answers into > perl-date-time/web/htdocs/faq.html ? Sure. I've been meaning to get around to adding some dynamic FAQ code to the site, but that's no reason to not start a pure-HTML version for now. -dave /*======================= House Absolute Consulting www.houseabsolute.com =======================*/ FAQ said: > 2.3: Why do I need to...

FAQ
How can I change the default directory for when I clic on the "Attach a file" icon ? It used to be that it would take me to the last directory used, but lately, when I attach a file, it always takes me to the same "specific" directory. Is this something that can be changes? Thanks in advance. -- MarioLacroix ------------------------------------------------------------------------ Try this: HKCU\Software\Novell\GroupWise\Client\Files Locations "Default Attach"= (REG_SZ) Regards Rolf Lidvall Swedish Radio (Ltd) ...

FAQ
Hello, Is there a faq for this list? or should we/I start one? jonasbn ...

faq
Hello, I have a question about the Parrot FAQ. I hope it's not too off-topic for this list. The FAQ mentions that "it would be nice to write the Perl to Bytecode compiler in Perl" and that there is no bootstrap problem. Does this mean that the perl6 compiler is written in perl5 and it will be rewritten in perl6 when a large enough subset of perl6 is implemented? I figure Perl5 will be obsolete at some point in the future... I noticed that the current incomplete perl6 implementation is written in perl5 using Parse::RecDescent, but I figured it's just a test imple...

Web resources about - Login control FAQ : - asp.net.faq

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...


Grand Mufti of Australia in damage control after Paris attacks
AUSTRALIA’S top Muslim cleric has gone into damage control.

69 percent of users would bypass security controls to win a big deal
When faced with the chance of clinching a major deal people are willing to throw security controls out of the window. This is according to research ...


Obama to Veto Bill Requiring Background Checks On Syrian Refugees; France Demands Tighter Controls, EU ...
... does not call for ending the refugee program or require religious screenings, as some Republicans have demanded . France Demands Tighter Controls, ...

Apple's new patent wants you to control notifications with your eyes
... technology either. Back in January 2015, it was granted a patent for a graphical user interface that would track your gaze and let you control ...

2 Killed After Helicopter Spins Out Of Control, Bursts Into Flames At Southern California Airport
Two people on board a helicopter were killed when the aircraft spun out of control after landing and burst into flames in Carlsbad.

Microsoft debuts controls that postpone Windows 10 feature upgrades up to a year
... delay Windows 10 feature upgrades for up to a year after consumers begin running the operating system's latest changes. New options for controlling ...

‘The Gun Control Song’ Channels Billy Joel To Troll Libs … Is Internet Gold
‘The Gun Control Song’ Channels Billy Joel To Troll Libs … Is Internet Gold

resources last updated: 11/20/2015 1:27:08 PM