ViewState & Machine Keys / MachineKeys Program
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
I'm going to make a confession to you. We talked about generating machine keys back in a few videos ago and then we talked about what it's going to take to generate a machine key and I went through a process of demonstrating how to load Internet Information Server 7 though if you didn't have it. Then later I went to bed that night and I'm thinking, you know, you just need to go out there and build that program for them and make it available to them. It's the least you can do. I'm going to throw this in here as a bonus. I sound like an infomercial, I know, but I'm going to include that machine keys program in the Work Files folder so look in the Work Files folder and you will see something called MachineKeys.exe. Now let me give you the disclaimer. This is a command-line application that will generate these machine keys for you. You won't have to install IIS 7.0. You can do that if you like if you have time. What I did and I want to make sure you understand this, is if you go out there and do that search like I mentioned back in I think Generating a Machine Key video, if you go out there to Microsoft.com and do a search on that How to Configure Your Machine Key in ASP.NET 2.0, they have some code on that page and so I just took that code, dropped it into Visual Studio, compiled the program and that's what I have put out there in the Work Files folder. So if you have any problems with it, there's no support here. Don't e-mail me with questions about it necessarily because I'm just going to point you back to that page and tell you to look at that code and figure it out. But I did want to put this in here because I think it'll help you tremendously, especially those of you, I really started feeling guilty because I realized some of you guys aren't very familiar with Visual Studio 2008 and this whole Windows program thing so I thought I would build this for you and put it out there and save you that hassle. So what you're going to have to do though is when you get this program, run it twice. The first time the key it generates is going to be for the validation key portion that's going to go in the Web.config file and the second time you run it, that key you're going to use for the decryption key. They both have to be different. Now, Microsoft has some guidelines for generating these key sizes and I'm going to go show you an example of running this in just a second here. These are Microsoft's guidelines. They're off of that same page. You can read them yourself but to generate a validation key that's based on SHA1 or S-H-A 1, they're saying to run machine keys and pass it the number 64. This will create a 128-hex character key. This is a 64-byte key. If you want to use for the decryption key the AES encryption algorithm or encryption type, you'll run machine keys and pass 32. So just type machine keys 32. This will create 64-hex characters and for 3DES, if you want to use this for the decryption key, then you're going to run machine keys 24. This will create 48-hex characters. OK? So let me go show you an example of what this looks like. Now, what you'll need to do it the way I'm doing it here and notice I'm going to click on Start, Run and I'll just type Command, C-M-D here to get to a command prompt. I have copied machine keys just right into the C Folder of my computer and if I type Directory here, you will notice that there is machine keys right here, MachineKeys.exe and so I'm going to clear this off and to run this I just type Machine Keys and for example if I'm going to use AES, I want to pass 32 and just hit Enter and there is your key. Now, you'll have to copy it out of here into your Web.config file. I Enter to end the program. To copy this, if I left click up here on the little icon and come down to Edit and choose Mark, I can now move the cursor and I get on top of that and hold down the Shift Key and paint over this and I will paint over everything that I want to copy and I will come back up here and choose Edit, Copy. Now at that point I can open say Notepad or something and let me see if I can't get to it here. We'll, I'll just open a Sticky Note right here. Then if I right click and paste, you'll see there is that code. I've got it on the Clipboard. But just make sure that you understand that you will have to left click up here, go to Edit and Mark and then hold down the Shift Key when you get to where you want to go to select what you want and then just come back up here, Edit, Copy. Now, notice if I want to run machine with, say like right here, this 64, I just type Machine Keys 64 and you'll notice it generates a longer key. So we had 64, 32 and then 24 and I'll have to run. You know how it's going to work, Machine Keys, 24 and it generates it shorter. This is how to generate your machine keys; very, very simple to copy MachineKeys.exe out of your Work Files folder, put it in a place, you'll have to go to that directory wherever you dropped that application. You will notice, let me show you, let me get out here to Start. If I go into Computer and go into, there's the Machine Keys program right there. Just drop that onto your hard disk and then move yourself to that directory and you can use that program. I hope that helps. Use that. That's one good way to generate the machine keys that you're going to need to provide this encryption and so forth between remote ASP.NET web servers.
Tutorial Information
| Course: | Microsoft ASP.NET 3.5 |
| Author: | Mark Long |
| SKU: | 34102 |
| ISBN: | 1-93633412-7 |
| Release Date: | 2010-03-24 |
| Duration: | 6 hrs / 69 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 