Use the membership class to determine whether a user exists

Source: Internet
Author: User
Use the membership class to determine whether a user exists
------------------------- Proficient in ASP. net2.0 enterprise-level project development and learning notes
Some time ago I bought the enterprise-level project development proficient in ASP. net2.0 published by the People's post and telecommunications Publishing House. For me who lack the enterprise-level project experience, I may be attracted by the enterprise-level projects. After a period of study, I found that this book has some advantages for beginners like ours, but there are also many errors. Here, I will record the problems I found in my study, I hope to help new users at the same level as me and also a summary of their own learning.
In the OA system development of this book Code

Public   Bool Sendmsg ( String Receive, String Send, String Title, String Content)
{
// First, you must determine whether the entered user name is correct.
If (Membership. findusersbyname (receive) =   Null )
Return   False ;
Else
 

This is a piece of code in the message sending method, which is intended to use membership. finduserbyname () determines whether the input user exists. If so, the sending operation is just executed. If not, a false value is returned. However, during the unit test, I found that the operation of sending information is performed no matter whether the user exists or not, and a sending record is added for querying database table files. By checking msdn, we found that the finduserbyname method returned a set of membershipusercollection. Through tracking, we found that even if the user does not exist, it is impossible to return a null value. another membership method getuser () in msdn caught my attention. setProgramThe changes are as follows:

Public   Bool Sendmsg ( String Receive, String Send, String Title, String Content)
{< br> // first, you must determine whether the user name is correct.
If (membership. getuser (receive) = null )
return false ;
else

run the test, and the program runs as expected

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.