Asp.NetÈÏÖ¤ºÍÊÚȨÀ©Õ¹
ÔÀ´µÄMembership
ÎÒÃÇÖªµÀÔÚAsp.Net 2.0ÖÐ΢Èí¾ÍΪÎÒÃÇÌṩÁËÇ¿´óµÄȨÏÞ¹ÜÀí¹¦ÄÜÀ´°ïÖúÎÒÃǹÜÀíAsp.NetÏàÓ¦µÄȨÏÞ£¬ÆäʵËüÊǶÔÎÒÃǵÄÉí·ÝÈÏÖ¤ºÍȨÏÞ¹ÜÀíµÄÒ»ÖÖ³éÏó¡£ÕâÀï¼òµ¥µÄÁ˽âÒ»ÏÂMembership£º
ÎÒÃÇÓ¦¸ÃÖªµÀ΢Èí¹ØÓÚÈÏÖ¤·½Ãæ¸øÎÒÃÇÌṩÁËÈýÖÖÈÏÖ¤·½Ê½windows ¡¢Forms¡¢Passport,ÎÒÏëÊìϤAsp.NetµÄÓû§¶¼ÖªµÀÎÒÃÇʹÓÃFormsÈÏÖ¤Ó¦¸ÃÊÇ×î¶àµÄ¡£µ«ÊÇÓ¦¸ÃÖ¸³öµÄ¾ÍÊÇÕâЩֻÊÇÉí·ÝÈÏÖ¤·½ÃæµÄ£¬ºÍMembership³ÉÔ±¹ÜÀíÊÇ·Ö¿ªµÄ¶ø²»ÊÇÎÒÃÇÒªÓÃFormsÈÏÖ¤¾Í±ØÐëʹÓÃMembership¡£ÀýÈç¼ÙÉèÎÒÃǵÄÕ¾µãֻǣ³¶µ½Óû§µÄµÇ¼¶ø²»ÐèÒª½øÐÐÏàÓ¦µÄ½ÇÉ«»®·ÖÒÔ¼°Ê¹ÓÃMembership´´½¨Óû§µÈ·½·¨µÄ»°¾ÍÍêȫֻʹÓÃFormsÈÏÖ¤¾Í¿ÉÒÔÁË£¨ÏñֻʹÓÃFormsÈÏÖ¤µÄÇé¿ö£¬ÎÒÃÇÓû§×¢²á£¬Óû§Éí·ÝÈÏÖ¤¾Í±ØÐëÎÒÃÇ×Ô¼ºÀ´×öÁË¡£ÎÒÃÇ¿ÉÒÔ½¨Á¢Óû§±í£¬×¢²áµÄʱºòÖ»ÐèҪдÏàÓ¦µÄÓû§ÐÅÏ¢µ½±íÖУ¬µÇ¼µÄʱºò¶ÁÈ¡Êý¾Ý¿âÖÐÏàÓ¦µÄÐÅÏ¢×öÆ¥Å䣬Èç¹ûÕýÈ·¾ÍÖ´ÐÐFormsAuthentication.SetAuthCookie(UserName, false)¾Í¿ÉÒÔÁË£©¡£ÕâʱÎÒÃÇËùÓеÄÓû§ÐÅÏ¢¹ÜÀí¶¼ÊÇ×Ô¼ºÀ´×öµÄ£¬µ±È»Áé»îÐԺܸßÁË£¬ÎÒÃǽö½öÓõ½FormsÈÏÖ¤µÄ»ù±¾¹¦ÄÜ£¨ÏñûÓеǼ×Ô¶¯»Øµ½µÇ¼ҳÃæ¡¢µÇ¼֮ºó¿ÉÒÔÔÚÆäËûÈκÎλÖõõ½Óû§Ïà¹ØÐÅÏ¢µÈ£©¡£µ«ÊÇÈç¹ûÓû§ÈÏΪ×Ô¼º¹ÜÀíÕâЩÐÅÏ¢±È½ÏÂé·³£¬¶øÇÒÓÐʱºòÎÒÐèÒªÓõ½½ÇÉ«¹ÜÀíµÄ»°ÎÒÃǾͲ»µÃ²»Ìáµ½MembershipÁË£¬ÓÐÁËËüÕû¸öÉí·ÝÈÏÖ¤ºÍȨÏÞ¹ÜÀí¾ÍºÜÈÝÒ×ÁË¡£ÕâÀï˵һÏÂËüµÄ±¾ÖÊ£¬MembershipÖ®ËùÒÔÈÃÓû§ÄÇôËæÐÄËùÓûµÄ²Ù×÷¶ø²»ÐèдºÜ¶àµÄ´úÂëÊÇÒòΪËü±¾Ê¡×öÁË´óÁ¿µÄ·â×°£¬ºÜ¶àÈ˲»Ã÷°×Óû§ÐÅÏ¢´æ´¢ÔÚʲôµØ·½£¬ÆäʵËüÊÇ´æ´¢µ½ÁËASPNETDB.mdfÕâ¸öÊý¾Ý¿âÖС£Õâʱ³õѧÕß¾ÍÒÉÎÊÕâ¸öÊý¾Ý¿âÎÒûÓн¨Á¢°¡£¬¶øÇÒÎÒÔÚ´´½¨¹¤³ÌµÄʱºòҲû¿´µ½Õâ¸öÊý¾Ý¿â°¡£¬¿öÇÒÊý¾Ý¿âÁ¬½Ó×Ö·û´®ÔÚʲôµØ·½°¡£¿Õâ¸öÊý¾Ý¿âÊÇϵͳ×Ô¶¯½¨Á¢µÄ£¬ÊÇ×Ô¶¯¸½¼ÓµÄ£¬µ±Ê¹ÓÃMembershipÀàʱ×Ô¶¯´´½¨·ÅÔÚApp_DataÎļþ¼ÐµÄ£¬ÏµÍ³¸Õ¿ªÊ¼´´½¨Ê±ÓÉÓÚϵͳ²»ÖªµÀÊÇ·ñʹÓÃMembershipËùÒԿ϶¨µ±Ê±Ã»Óд´½¨£¬¶øÇÒÊý¾Ý¿âÁ¬½Ó×Ö·û´®ÊDZØÐëµÄ¿Ï¶¨Óеģ¬ËüÔÚMachine.configÖУ¬Õâ¸öÎļþ¾ßÌå×÷ÓÃÎÒÏë´ó¼ÒÓ¦¸Ã¿´¿´asp.netÔËÐлúÖƾÍÖªµÀÁË£¬ËüÊÇÓÅÏÈÓÚweb.configµÄÒ»¸öÅäÖÃÎļþ¡£MembershipÌṩÁË´´½¨Óû§¡¢µÃµ½Óû§¡¢É¾³ýÓû§¡¢ÑéÖ¤Óû§µÈһϵÁеŦÄÜ£¬¶øÇÒÓëRole½ôÃܽáºÏ¹ÜÀíÓû§½ÇÉ«¡£³ý´ËÖ®Íâ΢Èí»¹ÌṩÁËÏàÓ¦µÄ¿Ø¼þʹÓû§¸ü¼ÓÈÝÒ×µÄʹÓÃMembership¡£
MembershipÀ©Õ¹
MembershipÄÇôºÃ£¬ÎÒÃǶ¼ÓÃËü²»¾ÍÐ
Ïà¹ØÎĵµ£º
ÉÏ´Î×öÁ˸öÏîÄ¿£¬Éæ¼°µ½Êý¾Ý¿âµÄ»¹ÔºÍ»Ö¸´£¬µ½ÍøÉÏÕÒÁËһϣ¬ÊÇÀûÓÃSQLDMOʵÏֵģ¬Ö»ÒªÌí¼ÓSQLDMOÒýÓþͺÃÁË£¬
È»ºóÀûÓÃϱߵÄÀàµÄ·½·¨¾Í¿ÉÒÔʵÏÖÁË¡£
ÎÒ°ÑÔ×÷ÕßµÄÀàÀ©³äÁËһϣ¬¿ÉÒÔ×Ô¶¯Ê¶±ðweb.configÀï µÄÊý¾Ý¿âÁ¬½Ó×Ö·û´®£¬¿ÉÒÔͨ¹ý±äÁ¿ÉèÖû¹Ô»Ö¸´µÄÐÅÏ¢¡£
ÐèҪעÒâµÄʱ»¹Ô£¬»¹ÔµÄʱºòÎÊÌâ ......
ÔÚÈÕ³£Ñ§Ï°ºÍʹÓÃASP.NETµÄ¹ý³ÌÖУ¬ÓÐЩ±È½ÏÌØÊâÓÐÓõľÑéÊÕ¼¯ÔÚÕâÀ·½±ã×Ô¼º¼ÇÒäºÍÀí½â£¬Ò²Ï£ÍûÄÜ°ïÖúµ½Ò»Ð©³õѧÕ߲ο¼¡£Èç¹ûÓÐЩ²»×ãµÄµØ·½Ï£Íû¸ßÊÖ²»Áߴͽ̣¡£¡£¡
Ò»¡¢ÔÚÒ»°ã´¦ÀíÎļþ(ashx)ÖÐʹÓÃSessionʱ£¬ÐèÒªÒý½øÃüÃû¿Õ¼ä£ºusing System.Web.SessionState; ²¢ÇÒʹ¸ÃÀàÊµÏ ......
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Sy ......
1.²ÉÓÃÁ÷È¡µÃͼƬ´óС¡¡
Stream stream=file.PostedFile.InputStream;
System.Drawing.Image image=System.Drawing.Image.fromStream(stream);
Image.Width
Image.Height
2.ʹÓÃÎļþµÃµ½Í¼Æ¬´óС
System.Drawing.Image image=System.Drawing.Image.fromFile£¨Í¼Æ¬Â·¾¶£©
Image.Width
Image.Height ......
Ö±½Ó°ÑÊý¾Ý¿â·ÅÖÃApp_dataÎļþ¼ÐÖУ¬Ìí¼ÓÒ»¸öweb.configÅäÖÃÎļþÈ»ºóдÈçÏ´úÂë
<connectionStrings>
<add name="users" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Users.mdf;Integrated Security=True;User Instance=True" providerName="System.Data ......