asp.net ÊÂÎñÀý×Ó
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn;
SqlCommand cmd1, cmd2;
SqlTransaction tra;
conn = new SqlConnection("server=.;database=test;uid=sa;pwd=123");
conn.Open();
tra = conn.BeginTransaction();//¿ªÊ¼ÊÂÎñ
cmd1 = new SqlCommand("update Test set StuName='¼Ñ¶ù' where StuScore=111", conn);
cmd2 = new SqlCommand("update Test set StuName='fdsafdsafdsfdsafsfsdadsadsadfsafsfsfdf' where StuScore=222", conn);
try
{
cmd1.ExecuteNonQuery();//´Ë¾ä¿ÉÒԳɹ¦Ö´ÐÐ
cmd2.ExecuteNonQuery();//´Ë¾ä¹ÊÒâÈÃÆäÖ´ÐÐʧ°Ü
tra.Commit();//ÎÞÒì³££¬Ìá½»ÊÂÎñ(Á½¾äÖ´Ðж¼ÓÐЧ)
Response.Write("<mce:script type="text/javascript"><!--
alert('Ö´Ðгɹ¦')
// --></mce:script>");
}
catch
{
tra.Rollback();//³öÏÖÒì³££¬»Ø¹öÊÂÎñ(Á½¾äÖ´Ðж¼ÎÞЧ)
Response.Write("<mce:script type="text/javascript"><!--
alert('Ö´ÐÐʧ°Ü')
// --></mce:script>");
}
finally
{
conn.Close();
}
} 0 0 0
(ÇëÄú¶ÔÎÄÕÂ×ö³öÆÀ¼Û)
Ïà¹ØÎĵµ£º
ASP.net´íÎó´¦Àí(´íÎóÌø×ªÒ³ webconfig)
ʹÓö¨ÖÆ´íÎóÒ³Ãæ
ËäÈ»ÎÒÃÇ·¢Ë͸øÓû§µÄ¹«ÓôíÎóÐÅÏ¢Êǰ²È«µÄ£¬¾ÍÊÇ˵Ëü²»»áÍþвµ½Ó¦ÓóÌÐòµÄÃØÃÜ£¬µ«ÊÇÕâÑùµÄÐÅÏ¢²¢²»ºÃ¿´¡£Ò²ÐíÄãÏ£ÍûÓû§ÓÀÔ¶Ò²¿´²»µ½ÕâÑùµÄÐÅÏ¢¡£Ïà·´£¬µ±´¦ÀíÇëÇóµÄ¹ý³ÌÖУ¬Èç¹û·¢ÉúÁËÒ»¸öΪ´¦ÀíµÄ´íÎó£¬ÄãÏ£ÍûÄܹ»ÏÔÊ¾× ......
1¡¢Í¨¹ý¸½¼ÓÒ»¸öcookiecontainerµ½httprequest¶ÔÏóÖУ¬¿ÉÒԵõ½µÇ¼ºó·µ»ØµÄ´ú±íSESSION IDµÄCOOKIE¡£
2¡¢½«´ËCOOKIE°üº¬ÔÚÒ»¸öcookiecontainerÖв¢¸½¼Óµ½ÁíÒ»¸öHTTPREQUESTÇëÇóÖУ¬Ôò¿ÉÒÔʵÏÖSESSIONµÄ»¹Ô¡£
²¿·ÖÖ÷Òª´úÂ룺
CookieContainer cookieContainer =& ......
Default..aspx
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
Default..aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.We ......
#region ÓòÃû°ó¶¨·½·¨
public static void AddHostHeader(int siteid, string ip, int port, string domain)//Ôö¼ÓÖ÷»úÍ·£¨Õ¾µã±àºÅ.ip.¶Ë¿Ú.ÓòÃû£©
{
DirectoryEntry site = new DirectoryEntry("IIS://localhost/W3SVC/" + siteid) ......
Ò»¡¢
Js
ÉèÖÃĬÈϰ´Å¥
function
document.onkeydown()
{
var
e=event
.srcElement;
&nbs ......