views:

649

answers:

4

This is an offshoot of this question.

  • How do I use a Login control if I don't have a MembershipProvider to point it at?
  • Am I understanding the use model correctly?
  • Is it even reasonable to talk about using a Login control without a MembershipProvider?
  • Dose the MembershipProvider do more than just username/password checking?
  • Would it be more reasonable to create my own MembershipProvider with the same authentication logic?

In my case, I don't need a MembershipProvider (I think) as my authentication situation is trivial (one user, one password).

I'm interested partly to "future proof" my page and partly because I'm new and wondering about how stuff works. (I tend to learn about things by running full speed into every corner case I can find :)

+2  A: 

Use Simple Forms Authentication.

Dan Diplo
That might work in my case but it doesn't answer the question.
BCS
+3  A: 

If you don't have a membership provider and don't really have a security system to speak of, just put two boxes on a form (user name, password) and test it in the onclick of the button.

The login control is obviously overkill for what your trying to do.

Chris Lively
you are probably correct... for now. Also that forces me to figure out how to deal with cookies and redirection and whatnot.
BCS
I don't mean to be blunt, but if you are having problems creating a cookie or redirecting the user then your not going to understand how to build a custom membership provider.. Which is what you would need in order to get the login control to work.
Chris Lively
I'm not having trouble creating a cookie, I just haven't ever worked with it and would rather not have to learn right now.
BCS
+4  A: 

Hi,

You can just drop the asp:Login control in your page, then in the code behind, catch the Login Control's Authenticate event.

In the Authenticate event, check the username/password that the user has entered. The username/password are properties in the login control. (Login.UserName, Login.Password)

If the username/password is correct, just set the event args Authenticated property to True.

No membership provider is required.

ex. In the aspx page..

<asp:Login ID="LoginCtrl" runat="server" DestinationPageUrl="YouAreIn.aspx"></asp:Login>

In Code Behind

Private Sub Log_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles LoginCtrl.Authenticate
    If LoginCtrl.UserName = "Hello" AndAlso LoginCtrl.Password = "Hello" Then
        e.Authenticated = True
    End If

c#

void MyLogin_Authenticate(object sender, AuthenticateEventArgs e)
{
    if(UserName == "Hello" && Password == "Hello")
        e.Authenticated = true;
}
Justin Largey
+1 - That's what I do
Juan Manuel
Also, to force the user to go to the login page, use forms authentication.
Justin Largey
If only it were so easy. I just tried it and the login jumps directly back into the login page rather than the page it was redirected from.
BCS
I'm already using Forms authentication.
BCS
BCS - Did you set the DestinationPageUrl?
Justin Largey
No, but every source I've found up to now indicates that the default will be the page that redirected to the login page.
BCS
Apologies, forgot to mention to set the DestinationPageUrl to the page the user is suppose to be redirect to. I have a working sample in case you need it.
Justin Largey
in your web.config are you denying anonymous users? <authorization> <deny users="?"/> <allow users="*"/> </authorization> also, here's my authentication settings, just for reference. <authentication mode="Forms"> <forms loginUrl="login.aspx" protection="All" path="/" timeout="30"></forms> </authentication>
Justin Largey
the comments don't seem to format XML properly. When you say referring page, do you mean the page the user was one to get to your login page? or the page the user was access before being prompted to login? or something else?
Justin Largey
Oh,.. crap:.. s/\*/\?/
BCS
After fixing `web.conf` it works without setting `DestinationPageUrl`.
BCS
oh, cool, did you set the defaultUrl in the web.config instead?
Justin Largey
Nope, it works as expected: if left unset, it goes right back to the page that redirected to `Loging.aspx` whatever that happens to be this time.
BCS
right, cool stuff, thanks for letting me know
Justin Largey
A: 

You would have to make a custom authentication provider and plug it in via web.config. http://www.devx.com/asp/Article/29256

Andrew Siemer