在ASP.NET中對文本框中字符串加密
//給輸入內容加密
TextBox2 .Text =FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1 .Text ,"MD5");//還有一種加密方式("SHA1"))
程序-VS2005-VS2005 Tools-命令提示;(第三個參數是你項目所在的文件)
//加密
aspnet_regiis.exe -pef "connectionStrings" "D:/MyBookShop/Web" -prov "DataProtectionConfigurationProvider"
//解密
aspnet_regiis.exe -pdf "connectionStrings" "D:/MyBookShop/Web"
!!!!這個操作只能在同一臺電腦上操作!!!!!
!!!!Web項目不能包含中文字符及特殊字符!!!
----身份驗證,驗證用戶是否擁有相應的身份
----權限驗證,控制各種身份的用戶擁有身份的權限
表單身份驗證示例:在<system.web>中進行配置
通過 <authentication> 節可以配置 ASP.NET 使用的
安全身份驗證模式,
以標識傳入的用戶。
-->
<authentication mode="Forms">
<forms name ="huiyuan" loginUrl ="Login.aspx" timeout="60"></forms>
</authentication>
<authorization>
<!--<deny users ="?"/>
<deny users="*"/>-->
<allow roles ="admin"/>
</authorization>
可以在後臺代碼給用戶創建身份(示例):
if ((txtUserName.Text.Trim() ==lu.UserName) && (txtPwd.Text.Trim() == lu.UserPassword))
{
FormsAuthentication.SetAuthCookie(txtUserName .Text .Trim (),true);//創建身份(基於cookie的身份驗證)
//FormsAuthentication.SignOut();//刪除身份驗證
string url = Request.QueryString["ReturnUrl"].ToString();//獲取之前訪問的頁面
Session["typeid"] = lu.TypeId.TypeId;
Response.Redirect(url);//取得驗證後跳轉到之前的頁面
}
自定義錯誤的設置(示例):在<system.web>中進行配置
<customErrors mode="On" defaultRedirect="Error.htm">
<error statusCode="403" redirect="NoAccess.htm" />//沒有權限的頁面
<error statusCode="404" redirect="FileNotFound.htm" />//頁面不存在時的頁面
</customErrors>