MVC4FormsAuth.Managers/UserManager.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using MVC4FormsAuth.Types;
using MVC4FormsAuth.Types.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Security;
namespace MVC4FormsAuth.Managers
{
public static class UserManager
{
/// <summary>
/// Returns the User from the Context.User.Identity by decrypting the forms auth ticket and returning the user object.
/// </summary>
public static User User
{
get
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
// The user is authenticated. Return the user from the forms auth ticket.
return ((MyPrincipal)(HttpContext.Current.User)).User;
}
else if (HttpContext.Current.Items.Contains("User"))
{
// The user is not authenticated, but has successfully logged in.
return (User)HttpContext.Current.Items["User"];
}
else
{
return null;
}
}
}
/// <summary>
/// Authenticates a user against a database, web service, etc.
/// </summary>
/// <param name="username">Username</param>
/// <param name="password">Password</param>
/// <returns>User</returns>
public static User AuthenticateUser(string username, string password)
{
User user = null;
// Lookup user in database, web service, etc. We'll just generate a fake user for this demo.
if (username == "admin" && password == "51aspx")
{
user = new User { Id = 123, Name = "John Doe", Username = "johndoe", Age = 21 };
}
return user;
}
/// <summary>
/// Authenticates a user via the MembershipProvider and creates the associated forms authentication ticket.
/// </summary>
后面还有 53 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。