本文整理汇总了C#中IHttpRequest.SaveSession方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpRequest.SaveSession方法的具体用法?C# IHttpRequest.SaveSession怎么用?C# IHttpRequest.SaveSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpRequest
的用法示例。
在下文中一共展示了IHttpRequest.SaveSession方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
base.Execute(req, res, requestDto);
var session = req.GetSession();
if(session!=null && session.IsAuthenticated)
{
req.SaveSession(session);// refresh session TTL
}
}
示例2: HasAllRoles
public bool HasAllRoles(IHttpRequest req, IAuthSession session, IAuthRepository userAuthRepo=null)
{
if (HasAllRoles(session)) return true;
session.UpdateFromUserAuthRepo(req, userAuthRepo);
if (HasAllRoles(session))
{
req.SaveSession(session);
return true;
}
return false;
}
示例3: HasAllRoles
public bool HasAllRoles(IHttpRequest req, IAuthSession session, IUserAuthRepository userAuthRepo=null)
{
if (HasAllRoles(session)) return true;
if (userAuthRepo == null)
userAuthRepo = req.TryResolve<IUserAuthRepository>();
if (userAuthRepo == null) return false;
var userAuth = userAuthRepo.GetUserAuth(session, null);
session.UpdateSession(userAuth);
if (HasAllRoles(session))
{
req.SaveSession(session);
return true;
}
return false;
}
示例4: Execute
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
base.Execute(req, res, requestDto);
var session = req.GetSession();
if(session!=null && session.IsAuthenticated)
{
req.SaveSession(session);// refresh session TTL
var cache = req.TryResolve<IRedisClientsManager>();
if(cache!=null){
using(var client = cache.GetClient()){
var pattern = string.Format("urn:{0}:*", req.GetSessionId());
var keys =client.SearchKeys(pattern);
foreach(var k in keys) {
client.ExpireEntryIn(k, AuthProvider.DefaultSessionExpiry);
}
}
}
}
}
示例5: ApiSignIn
public static void ApiSignIn(ref Container container, ref IHttpRequest req, ref IHttpResponse res)
{
if (req.QueryString["apikey"] != null)
{
var repository = container.Resolve<IRepository>();
var authRepo = (OrmLiteAuthRepository)container.Resolve<IUserAuthRepository>();
int userAuthId = int.Parse(req.QueryString["apikey"].Split('|')[0]);
string apiKey = req.QueryString["apikey"].Split('|')[1];
var users = repository.Find<User>(u => u.UserAuthId == userAuthId && u.ApiKey == apiKey);
if (users.Count() > 0)
{
UserAuth userAuth = authRepo.GetUserAuthByUserName(users[0].UserName);
CustomUserSession user = userAuth.TranslateTo<CustomUserSession>();
user.IsAuthenticated = true;
user.UserAuthId = users[0].UserAuthId.ToString();
req.SaveSession(user);
}
}
}
示例6: AutoSignIn
public static void AutoSignIn(ref Container container, ref IHttpRequest req, ref IHttpResponse res)
{
string authSession = string.Empty;
if (req.Cookies.ContainsKey("auth-session"))
{
if (string.IsNullOrEmpty(req.Cookies["auth-session"].Value))
{
authSession = "0";
res.Cookies.DeleteCookie("auth-session");
}
else
{
authSession = req.Cookies["auth-session"].Value;
}
}
if (!req.GetSession().IsAuthenticated && !string.IsNullOrEmpty(authSession))
{
// Auto sign-in the user:
var repository = container.Resolve<IRepository>();
var authRepo = (OrmLiteAuthRepository)container.Resolve<IUserAuthRepository>();
int userAuthId = int.Parse(authSession.Split('|')[0]);
string apiKey = authSession.Split('|')[1];
var users = repository.Find<User>(u => u.UserAuthId == userAuthId && u.ApiKey == apiKey);
if (users.Count() > 0)
{
UserAuth userAuth = authRepo.GetUserAuthByUserName(users[0].UserName);
CustomUserSession user = userAuth.TranslateTo<CustomUserSession>();
user.IsAuthenticated = true;
user.UserAuthId = users[0].UserAuthId.ToString();
req.SaveSession(user);
}
}
else if (req.GetSession().IsAuthenticated && string.IsNullOrEmpty(authSession))
{
// Create the auto sign-in coookie:
var repository = container.Resolve<IRepository>();
int userAuthId = int.Parse(req.GetSession().UserAuthId);
User user = repository.Find<User>(u => u.UserAuthId == userAuthId).FirstOrDefault();
res.Cookies.AddPermanentCookie("auth-session", req.GetSession().UserAuthId + "|" + user.ApiKey);
}
}