Click here to Skip to main content
15,889,716 members
Articles / Operating Systems / Windows 2008 R2

How to Generate Machine Key in IIS7

Rate me:
Please Sign up or sign in to vote.
4.33/5 (8 votes)
6 Jul 2011CPOL1 min read 90K   11   3
Machine key generates a unique key which helps you on single form because it helps to protect your Form Authentication cookies and page level View state

Introduction

Machine key generates a unique key which helps you on single form because it helps to protect your Form Authentication cookies and page level View state. When user sends a request and Server A receives response with form Authentication cookies, now again he sends a request which was received by Server B and attempted to decrypt form authentication cookies which was unsuccessful to decrypt because server A was using his own unique machine key and server B was using its own unique machine key to decrypt the form Authentication cookies. To avoid this problem, use the same machine key on all servers.

Generate Machine Key in IIS7

Let’s see the example on how to generate machine key for web site.

  • Open your IIS Manager from Administrative tool -> Internet Information Services Manager.
  • In Connection pane on left side of window, click on the website.

Image 1

  • Double click on Machine Key icon as shown below.
  • You will see Machine key page, default encryption method is SHA1, you can change it from dropdown list as shown.
  • Click on Generate Keys from Actions pane from left side of IIS window as shown.

Image 2

  • Click Apply as shown.

Image 3

  • Message will be shown on Alerts pane, "The changes have been successfully saved."

Image 4

  • Open your Web.Config file, you will find the <machineKey> inside the <system.web> section as shown.

Web.Config

XML
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
     <system.web>
        <machineKey decryptionKey="43B77C7F7CCC3CDEF3AD3493D520C203D0E4A5D8EFB9FA52"
validationKey="7225EEAECE4ACD976C7F13D47C4BAC40C88EC24535F9B639D1CBDCB4A342163CCFB6
D7B86602F03F77E5A149055E30A11771225ED83D03FB41B01A3E93E921F9" />
    </system.web>
</configuration> 
Note: Apply this machine key on all web farm servers; this is my generated machine key.

Link

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Dotnetplace
Pakistan Pakistan
Aamir Hasan is a Sr. Software Engineer and Technical Lead in a US based firm, having five years of experiences working in Software Design, Software Analysis, Business Intelligence, Web Development, Consultancy and Training, using SQL Server, .NET Framework and provides consultancy on how to design and develop .NET application with database solutions. Aamir is the founder of www.aspxtutorial.com and dotnetplace.com. He is a Microsoft Certified and SEO professional too. He is capable of coordinating off-shore high level web development projects.


asp.net Tutorial, sample code and demo

Comments and Discussions

 
GeneralSimple and Good Pin
Arkadeep De30-Mar-15 1:26
professionalArkadeep De30-Mar-15 1:26 
Really a simple but good one..

GeneralMy vote of 4 Pin
vishal_dj8814-Feb-13 8:06
vishal_dj8814-Feb-13 8:06 
QuestionGood tips Pin
Ethan Woo21-Jul-11 15:35
Ethan Woo21-Jul-11 15:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.