ASP.NET¼¼ÇÉ£ºÊ¹ÓÃGridview°ó¶¨Êý¾Ý¿âÖеÄͼƬ
ʹÓÃGridview°ó¶¨Êý¾Ý¿âÖеÄͼƬ
×¢£º´ËϵÁмǼÔÚÎÒʵ¼Ê¿ª·¢ÖÐÓöµ½µÄÎÊÌâºÍÊÕ²ØһЩ¼¼ÇÉÎÄÕ¡£
ÎÒÃǶ¼ÖªµÀ£¬ÔÚGridviewÖв»ÄÜÖ±½ÓÈ¥°ó¶¨Êý¾Ý¿âÖеÄͼƬ£¬ÎÒÃÇ¿ÉÒÔÀûÓÃHttpHandlerºÜÈÝÒ×µÄÍê³ÉÕâ¸öÈÎÎñ£¬ÔÚÕâÀïÎҼǼһÏÂÕâ¸ö¹ý³Ì¡£
1.ÉÏ´«Í¼Æ¬´æ´¢µ½Êý¾Ý¿âÖÐ
ÔÚÊý¾Ý¿âÖд´½¨Ò»¸ö±í£¬Ìí¼ÓÒ»ÏÂ3¸ö×ֶΣº
²½ÖèÒ»£ºÔÚWebÒ³ÃæÖÐÍÏÒ»¸öFileUpload ¿Ø¼þ£¬Ò»¸öÎı¾¿òÓÃÓÚÊäÈëÃû³ÆºÍÌá½»ÉÏ´«°´Å¥
<asp:FileUpload ID="fuImage" runat="server" /><br />
<asp:TextBox ID="txtImageName" runat="server"/><br />
<asp:Button ID="btnUpload" runat="server" onClick="btnUpload_Click" Text="Upload" />
²½Öè¶þ£ºÔÚWeb.ConfigÎļþÄÚÅäÖÃÁ¬½Ó×Ö·û´®¡£
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|\Image.mdf;Integrated Security=True;
User Instance=True" providerName="System.Data.SqlClient"/>
²½ÖèÈý£º°ÑÏÂÃæµÄ´úÂ븴ÖƵ½ÉÏ´«°´Å¥Ê¼þÖС£
protected void btnUpload_Click(object sender, EventArgs e)
{
Stream imgStream = fuImage.PostedFile.InputStream;
int imgLen = fuImage.PostedFile.ContentLength;
string imgName = txtImageName.Text;
byte[] imgBinaryData = new byte[imgLen];
int n = imgStream.Read(imgBinaryData,0,imgLen);
//use the web.config to store the connection string
SqlConnection connection = new SqlConnection(ConfigurationManager.
ConnectionStrings["connectionString"].ConnectionString);
SqlCommand command = new SqlCommand("INSERT INTO Image (imagename,image)
VALUES ( @img_name, @img_data)", connection);
SqlParameter param0 = new SqlParameter("@img_name", SqlDbType.VarChar, 50);
param0.Value = imgName;
command.Parameters.Add(param0);
SqlParameter param1 = new SqlParameter("@img_data", SqlDbType.Image);
param1.Value = imgBinaryData;
command.Parameters.Add(param1);
connection.Open();
int numRowsAffected = command.ExecuteNonQuery();
connection.Close();
}
2.ÀûÓÃHttpHandler´ÓÊý¾Ý¿âÖжÁȡͼƬ
´´½¨Ò»¸öÃû
Ïà¹ØÎĵµ£º
ÔÚWeb±à³Ì¹ý³ÌÖУ¬´æÔÚןܶలȫÒþ»¼¡£±ÈÈçÔÚÒÔÇ°µÄASP°æ±¾ÖУ¬CookieΪ·ÃÎÊÕߺͱà³ÌÕ߶¼ÌṩÁË·½±ã£¬²¢Ã»ÓÐÌṩ¼ÓÃܵŦÄÜ¡£´ò¿ªIEä¯ÀÀÆ÷£¬Ñ¡Ôñ“¹¤¾ß”²Ëµ¥ÀïµÄ“InternetÑ¡Ï¬È»ºóÔÚµ¯³öµÄ¶Ô»°¿òÀïµ¥»÷“ÉèÖÔ°´Å¥£¬Ñ¡Ôñ“²é¿´Îļþ”°´Å¥£¬ÔÚµ¯³öµÄ´°¿ÚÖУ¬¾Í»áÏÔʾӲÅÌÀï ......
×öÏîÄ¿Ò²ÓÐÒ»¶Îʱ¼äÁË£¬ÔÚ³ÌÐòÖÐÒ²Óöµ½ºÜ¶à°²È«·½ÃæµÄÎÊÌâ¡£Ò²¸Ã×ܽáÒ»ÏÂÁË¡£Õâ¸öÏîÄ¿ÊÇÒ»¸ö CMS ϵͳ¡£ÏµÍ³ÊÇÓà ASP.NET ×öµÄ¡£¿ª·¢µÄʱºò·¢ÏÖ΢Èí×öÁ˺ܶలȫ´ëÊ©£¬Ö»ÊÇÓÐЩÐÂÊÖ³ÌÐòÔ±²»ÖªµÀÔõô¿ªÆô¡£ÏÂÃæÎÒͨ¹ý¼¸¸ö·½Ãæ¼òµ¥½éÉÜ£º
¡¡¡¡1£ºSQL ×¢Èë
¡¡¡¡2£ºXSS
¡¡¡¡3£ºCSRF
¡¡¡¡4£ºÎļþÉÏ´«
SQL ×¢Èë
¡¡¡¡Ò ......
ASP.NET
¹«ÓÐÁùÖÖÑéÖ¤¿Ø¼þ£¬·Ö±ðÈçÏ£º
RequiredFieldValidator
£¨±ØÐë×Ö¶ÎÑéÖ¤£© ÓÃÓÚ¼ì²éÊÇ·ñÓÐÊäÈëÖµ
CompareValidator
£¨±È½ÏÑéÖ¤£© °´É趨±È½ÏÁ½¸öÊäÈë
RangeValidator
£¨·¶Î§ÑéÖ¤£© ÊäÈëÊÇ·ñÔÚÖ¸¶¨·¶Î§
RegularExpressionValidator
£¨ÕýÔò±í´ïʽÑéÖ¤£© ÕýÔò±í´ïʽÑéÖ¤¿Ø¼þ
CustomValid ......
¸Õ¿´µ½ÁËһƬÎÄÕ http://dotnet.csdn.net/page/a92a1213-9896-49c7-9c89-14ae5f0d87ae Ìáµ½Èçϼ¸µã:
1. Êý¾Ý¿âÁ¬½Ó³¬Ê±
2. ´´½¨µÄ¶ÔÏóÖ»¹ÜÓ㬲»¹ÜÊÍ·Å
3. µ÷ÊÔ(Debug)ģʽϱàÒëºó£¬¾ÍÓÃÓÚÓ¦Óû·¾³ÖÐÁË
4. ʵ¼Ê×÷ҵģʽ·ÖÏí
1,2,3±È½ÏºÃÀí½â£¬ÎÒÔÚ×öµÄʱºò·¸ÁËËû˵µÄ µÚÈýÖÖ´íÎó£¬ÖÁ ......