Learning PetShop3.0 (1) User Login (SignIn. aspx)
. Net has reached 2005, and Microsoft's PetShop3.0 has reached 4.0. Now we are still learning PetShop3.0, which is purely a supplement to the previous steps of learning. net. After all, there are some things you don't know if you don't read them. Most PetShop articles on the Internet refer to the architecture or language features. Therefore, we decided to analyze the most basic pages first.
Log on to the SignIn. aspx page. An img is used for registration and transferred to the new registration page. There is an imagebutton used to submit pages. It seems a good habit to set both img and alertText. The submit button calls the SubmitClicked method in the background.
1) (signIn. aspx. cs) PetShop3.0 is separated from the business entity and business logic, and also has logical processing in the presentation layer. For example, WebComponents. CleanString is used to check the validity of input.
String userId
= WebComponents. CleanString. InputText (txtUserId. Text, 50 );
String
Password = WebComponents. CleanString. InputText (txtPassword. Text, 50 );
First, judge the length of the input string. If the length exceeds the maximum length, the string is truncated. Then, replace some dangerous characters ', <> ,''.
For (int I = 0;
I <inputString. Length; I ++ ){
Switch
(InputString [I]) {
Case
'"':
RetVal. Append ("& quot ;");
Break;
Case
'<':
RetVal. Append ("& lt ;");
Break;
Case
'> ':
RetVal. Append ("& gt ;");
Break;
Default:
RetVal. Append (inputString [I]);
Break;
}
}
//
Replace single quotes with white space
RetVal. Replace ("'",
"");
2) (PetShop. Web. ProcessFolw. AccountController. cs) and then log on to the official account. AccountController. ProcessLogin (userId, password). The returned value indicates whether the logon is successful. Create an account class at the business layer and call account. SignIn (userId,
Password.
Determine whether the logon is successful by checking myAccountInfo.
Account account = new Account ();
AccountInfo
MyAccountInfo = account. SignIn (userId, password );
3) It seems to be one of the highlights of PetShop3.0. It makes full use of the features of the language itself to dynamically create the Dao layer, avoiding the disadvantages of those original creation modes. (PetShop. BLL. Account. cs) The method of account. SignIn is as follows.
Public
AccountInfo SignIn (string userId, string password ){
If (userId. Trim () = string. Empty)
| (Password. Trim () = string. Empty ))
Return null;
IAccount
Dal = PetShop. DALFactory. Account. Create ();
AccountInfo
Account = dal. SignIn (userId, password );
Return account;
}
Here PetShop. DALFactory. Account. Create () uses dependency injection. Use WebConfig to read the name of the class to be created. <Add
Key = "WebDAL" value = "PetShop. SQLServerDAL"/>. This class supports SQL. Create an Account instance at the DAL layer.
Public static PetShop. IDAL. IAccount Create ()
{
String path =
System. Configuration. ConfigurationSettings. receivettings ["WebDAL"];
String className = path + ". Account ";
Return (PetShop. IDAL. IAccount) Assembly. Load (path). CreateInstance (className );
}
4) (PetShop. DALFactory. Account. cs)
AccountInfo account = dal. SignIn (userId, password) starts access to the data layer. Enter the user name and password. If a return value exists, the user exists. Returns an AccountInfo object class.
5) (return to PetShop. Web. ProcessFolw. AccountController. cs) and log on to the start page. Return to the original login page. And save the account information to the session.
If (myAccountInfo! = Null)
{
HttpContext. Current. Session [ACCOUNT_KEY]
= MyAccountInfo;
If (FormsAuthentication. GetRedirectUrl (userId, false). EndsWith (URL_DEFAULT )){
FormsAuthentication. SetAuthCookie (userId,
False );
HttpContext. Current. Response. Redirect (URL_ACCOUNTSIGNIN,
True );
} Else {
FormsAuthentication. SetAuthCookie (userId,
False );
HttpContext. Current. Response. Redirect (FormsAuthentication. GetRedirectUrl (userId,
False), true );
}