Record the problem.
Problem description:
The website verifies the form and enables anonymity.
User A has never logged on to the website or configured any permissions for user A on the website. That is to say, if you do not enable Anonymous Access, A has no right to access the website.
Then, use A to log on to the website (anonymous access is enabled), and SPContext. Current. Web. CurrentUser will be null.
Solution:
Add User A or all authenticated users to the visitor group, or assign other permissions to user.
After the configuration is complete, log on with A again, And SPContext. Current. Web. CurrentUser will be able to work normally.
Cause:
If a user has not been assigned any permissions, the first time the user logs on to an anonymous website, the Sharepint does not register the user, but is processed as an anonymous user.
This will cause the above situation.