Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

Login Controls

0 (0 Likes / 0 Dislikes)
  • Embed Video

  • Embed normal player Copy to Clipboard
  • Embed a smaller player Copy to Clipboard
  • Advanced Embedding Options
  • Embed Video With Transcription

  • Embed with transcription beside video Copy to Clipboard
  • Embed with transcription below video Copy to Clipboard
  • Embed transcript

  • Embed transcript in:
    Copy to Clipboard
  • Invite a user to Dotsub
[Microsoft ASP.net] [www.ASP.net] [Joe Stagner] Hi folks—Joe Stagner here with Video #16 in this video series on building ASP.net web applications using Microsoft Visual Web Developer. Now, in this video we are going to take a very quick look at membership and authentication in Visual Web Developer. Now, one thing I want to point out is that this is just an introductory video. And, in fact, I've started a series of videos specifically on ASP.net membership and authentication here on the ASP.net website. So, if you're interested you can point your browser at ASP.net/learn/securityvideos. And you can look at all of the security videos that I've done so far, and most of the ones that I've done so far pertain to ASP.net membership and authentication. I also want to recommend this excellent resource on the subject by Stefan Schackow, who is a member of the ASP.net team, and this is just an amazing book. You can see that I ordered it several years ago—3½ years ago on Amazon. And I highly recommend this book if you want to drill down into the details of ASP.net security, membership, and role management. So, with that said, let's go ahead and look at Visual Web Developer. And what I've got here is rather than do a demo with no user interface, I've gone out to one of the free web template sites out there, and I've downloaded a template—let's have a look at— I'll just run this template. Just—you can see what the default looks like, and the only reason I want to do this is I want to use some sort of a realistic looking design so that we—I can show you membership-based authentication built into and existing web application rather than showing it to you just in a plain, white web form. And since I have virtually no artistic ability, I've selected a design from, I think I got this one from Free CSS Designs—yeah—FreeCSSTemplates.org. So—we're going to add some membership to this particular web form. Now, you'll notice here that I've included all the visuals in a master page, and if you're interested in how to do this—previously in this video series I did this very thing in the video on using master pages with Visual Web Developer. So, you can see exactly how I separated the visual interface that I downloaded from one of the free UI design sites into a master page, and then drive from that page when I create the default as ASP X page. So—the first thing that we need to do is look at the authentication mechanism for our current application, so I'm going to select the website menu here in Visual Web Developer. And then I'm going to choose ASP.net configuration. Now, as I mentioned, I've done a whole series of videos on this topic, so I'm not going to drill down too much into the details. I'm just going to hope that you'll go over to the ASP.net URL that I mentioned earlier and watch some of the videos there, but there are a couple things that we need to do to get started here, and the first is to set the security provider. Now, you'll notice here it tells us that the current authentication type is Windows, and I want to use forms-based authentication which means that I want to use ASP.net membership. So instead of from a local network, meaning I'm going to use Windows authentication, I'm going to select from the Internet, which will switch to forms authentication using the ASP.net membership system. Now, you might wonder how—how this tool knows what to do when I change my authentication type, and the reason it knows what to do—how to connect to authentication database— is that in the machine.config file, the default ASP.net membership database is specified—there's a connection string there. And—again—if you look at the previous videos that I just referred you to, I drill down into the details of how that works. So, we have a default that is specified in the machine.config file— of course we can change that if we want to here in our local applications web.config file. But in our case, we're just going to go with the default one, which is a SQL 2008 instance installed on my developer machine. The next thing I want to do is to create a user, so I'm going to really quickly just create a user name for myself; I'm going to enter a password. And we'll specify my email; I'm going to need a security question and an answer. I'm just doing this very quickly, and I'm going to create this user. So now that I've created this user, we can start to program against the user database and authenticate with the user that I just created. So let's close this out, go back into Visual Web Developer, and the first thing I want to do is here in our master page we want to add a login control. And certainly there is an entire API for programming against the membership store that is part of the ASP.net membership system. But in our case, we are just going to use the simple authentication controls that are available in the tool box in Visual Web Developer. So, let's switch over to our master page here, and scroll over and this is the place where we're going to want this to take place. So—I'm going to go into source view here, and you'll see why momentarily. And I just put these three dashes as a place marker. Now, let's go over to the tool box and scroll down until we find the login collection, and the login control is the one that we're going to use. But before we use that, I'm going to use the login view control. So, let's drop an instance to the log and view control on the page. And here—now you'll recall I'm actually in the master page because I want this login option to appear everywhere on the page—everywhere on my website, on each derived page if the user is logged in or not logged in. So, that's why I'm using the login view. So, inside the login view, I'm going to create an anonymous template and a logged in template. And what this does is this provides 1 set of rendering if the user is anonymous and a different set of rendering if the user is logged in. All right—so—I'm going to grab that because we're going to use it later. Here in the anonymous template, we're going to add a login control. So—if the user is not logged in—the anonymous template will show, and they'll get the login control; if the user is logged in then we could do whatever we want here, and maybe we pull—you know—the message of the day or whatever. So, I'll just add some static text message of the day. Now, the next thing I want to do is I'm going to go over to my default.ASPX page, and let's pop into source mode here. And here in this entry, inside our content control—all right—so this is just our default.ASPX page, which inherits from that master page. Let's—oh—let's also add a login view. And then, of course, inside the login view we need to add the templates for both anonymous and logged in. And if they're anonymous we can put one set of content— so say please register on our site. And then in the logged in template, we can put some other message— we love our members. Now, you could put any sort of controls here. You can do JavaScript manipulation. You can use ASP.net controls or HTML elements—whatever you want you can put in these various templates. But—just by doing that—by using the login view control and a login control as well in the anonymous template— let's have a look and see what our webpage looks like. So, you can see here—notice this message, "Please register on our site." And because we haven't logged in yet, notice we've got the login view, and the login control here, so I can add my user name and my password. And I can authenticate—so click login, and now here we see the message of the day and, "We love our members." So, just based on whether—the state of the application whether or not someone is logged in or not logged in, we can determine what they see. Now, we haven't added a way to log out yet. So, let's—let's just make 1 little change. Let's go back into our master page, and here at the message of the day let's add a login status control. All right—and that's all I'm going to do is just add that login status control. Now let's run our application again. Now, what if we entered a name that doesn't have an authentication account? Notice it tells us your login was not successful, so let's go ahead and login with a good user name and password. And notice that there's a logout option, so here, again, we'll log in. And notice this message of the day, and then there's this logout option. And if I click on logout, then I've been logged out. So that's just a real high-level, quick view of using ASP.net membership in your Visual Web Developer built ASP.net application. And I hope that you really go over and take a look over at ASP.net/learn/security/videos site where you learn all kinds of different things— both how to use all the controls that are part of the login control series as well as how to program directly using the membership API. And this video series will provide you with that detailed information. [Microsoft ASP.net] [www.ASP.net]

Video Details

Duration: 10 minutes and 28 seconds
Country: United States
Language: English
License: All rights reserved
Genre: None
Views: 8
Posted by: neudesicasp on Sep 5, 2013

In this video Joe will introduce you to ASP.NET Membership by showing you how to use some of the Login Controls in ASP.NET.

Caption and Translate

    Sign In/Register for Dotsub to translate this video.