4、配置身份验证
配置身份验证
Asp.net Framework支持三种验证类型
Windows身份验证
.net Passport身份验证
Forms身份验证
对于特定程序,同一时刻只能启用一种身份验证方式
默认情况下,系统将启用Windows身份验证。验证用户职责委派给了IIS
.Net Passport身份验证是诸如MSN和Hotmail这样的微软Web站点使用的验证类型。
Forms身份验证。启用Forms身份验证后,通常会使用Cookie来验证用户。
Web.Config
<configuration> <system.web> <authentication mode="Forms"> </authentication> </system.web></configuration>
<?xml version="1.0"?><configuration> <system.web> <authentication mode="Forms"> <forms cookieless="AutoDetect"/> </authentication> </system.web></configuration>
<?xml version="1.0"?><configuration> <system.web> <authentication mode="Forms"> <forms slidingExpiration="false" timeout="1"/> </authentication> </system.web></configuration>
<?xml version="1.0"?><configuration> <system.web> <machineKey decryption="Auto" validation="SHA1" decryptionKey="AutoGenerate,IsolateApps" validationKey="AutoGenerate,IsolateApps"/> <authentication mode="Forms"> <forms slidingExpiration="false" timeout="1"/> </authentication> </system.web></configuration>
<%@ Page Language="C#" %><%@ Import Namespace="System.Security.Cryptography" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { lblAES.Text = GetSequence(64); lblSHA1.Text = GetSequence(128); } private string GetSequence(int length) { byte[] buffer = new byte[length / 2]; RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider(); provider.GetBytes(buffer); StringBuilder builder = new StringBuilder(length); for (int i = 0; i < buffer.Length; i++) builder.Append(string.Format("{0:X2}", buffer[i])); return builder.ToString(); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <div> AES: <asp:Label ID="lblAES" runat="server" /> <br /> <br /> SHA1: <asp:Label ID="lblSHA1" runat="server" /> </div> </form></body></html>