code/Athena0.0.1/common/Util/Web/WebHelper.cs
(开头部分) 9KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Web;
using System.Web.Security;
namespace Athena.common.Util.Web
{
public class WebHelper
{
static string[] BeReplacedStrs = new string[] { ".com", ".cn", ".com.cn", ".edu.cn", ".net.cn", ".org.cn", ".co.jp", ".gov.cn", ".co.uk", "ac.cn", ".edu", ".tv", ".info", ".ac", ".ag", ".am", ".at", ".be", ".biz", ".bz", ".cc", ".de", ".es", ".eu", ".fm", ".gs", ".hk", ".in", ".info", ".io", ".it", ".jp", ".la", ".md", ".ms", ".name", ".net", ".nl", ".nu", ".org", ".pl", ".ru", ".sc", ".se", ".sg", ".sh", ".tc", ".tk", ".tv", ".tw", ".us", ".co", ".uk", ".vc", ".vg", ".ws", ".il", ".li", ".nz" };
/// <summary>
/// 从 cookieName 中获取有效的 FormsAuthenticationTicket
/// </summary>
/// <param name="cookieName"></param>
/// <param name="checkExpiration">是否验证票据的有效期</param>
/// <returns></returns>
public static FormsAuthenticationTicket GetTicketByCookieName(string cookieName, bool checkExpiration = false)
{
FormsAuthenticationTicket authTicket = null;
HttpRequest request = HttpContext.Current.Request;
HttpCookie authCookie = request.Cookies[cookieName];
if (authCookie != null && !string.IsNullOrEmpty(authCookie.Value))
{
try
{
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
}
catch (CryptographicException)
{
return null;
}
if (checkExpiration && authTicket.Expired)
{
return authTicket = null;
}
}
return authTicket;
}
public static string CreateEncryptedTicket(string name, DateTime expiration, string userData, bool isPersistent = false)
{
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, name, DateTime.Now, expiration, false, userData);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
return encryptedTicket;
}
/// <summary>
/// 从 cookieName 中获取有效 FormsAuthenticationTicket 的 Name,如果获取 Ticket 失败,则返回 null
/// </summary>
/// <param name="cookieName"></param>
/// <param name="checkExpiration">是否验证票据的有效期</param>
/// <returns></returns>
public static string GetTicketNameByCookieName(string cookieName, bool checkExpiration = false)
{
FormsAuthenticationTicket authTicket = GetTicketByCookieName(cookieName, checkExpiration);
后面还有 190 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
