当前位置: 首页>>代码示例>>C#>>正文


C# IOwinContext.GetSession方法代码示例

本文整理汇总了C#中IOwinContext.GetSession方法的典型用法代码示例。如果您正苦于以下问题:C# IOwinContext.GetSession方法的具体用法?C# IOwinContext.GetSession怎么用?C# IOwinContext.GetSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IOwinContext的用法示例。


在下文中一共展示了IOwinContext.GetSession方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Invoke

        public override Task Invoke(IOwinContext context)
        {
            //如果已经登录
            if (context.GetSession().ContainsKey(LOGINED_USER_KEY))
            {
                context.Environment[LOGINED_USER_KEY] = context.GetSession()[LOGINED_USER_KEY];
                return Next.Invoke(context);
            }

            var req = context.Request;
            var sourceRequestPath = req.Get<String>("Quick.OwinMVC.SourceRequestPath");
            if (sourceRequestPath == null)
                sourceRequestPath = req.Get<String>("owin.RequestPath");
            //如果是登录页面,则允许访问
            if (new PathString(sourceRequestPath).Equals(new PathString(loginPath)))
                return Next.Invoke(context);
            else
            //否则,跳转到登录页面
            {
                return Task.Factory.StartNew(() =>
                {

                    var rep = context.Response;

                    if (sourceRequestPath != null)
                        req.Set("owin.RequestPath", sourceRequestPath);
                    var returnUrl = req.Uri.ToString();
                    //对URL进行编码
                    returnUrl = System.Web.HttpUtility.UrlEncode(returnUrl);
                    var redirectUrl = $"{req.Get<String>("ContextPath")}{loginPath}?{RETURN_URL_KEY}={returnUrl}";
                    rep.Redirect(redirectUrl);
                });
            }
        }
开发者ID:HongJunRen,项目名称:Quick.OwinMVC,代码行数:34,代码来源:LoginMiddleware.cs

示例2: Service

 public string Service(IOwinContext context, IDictionary<string, object> data)
 {
     var rep = context.Response;
     context.GetSession().Clear();
     rep.Redirect(context.Get<String>("ContextPath"));
     return null;
 }
开发者ID:HongJunRen,项目名称:Quick.OwinMVC,代码行数:7,代码来源:LogoutController.cs

示例3: Service

 public override async Task<object> Service(IOwinContext context)
 {
     var method = context.Request.Method;
     var action = context.Request.Query["action"];
     switch (action)
     {
         case "modify_password":
             if (method != "POST")
                 return null;
             var formData = context.GetFormData();
             var account = context.GetSession()[LoginMiddleware.LOGINED_USER_KEY]?.ToString();
             var pre_password = formData.Get("pre_password");
             var new_password = formData.Get("new_password");
             try
             {
                 return await Task.FromResult(modifyPassword(account, pre_password, new_password));
             }
             catch (Exception ex)
             {
                 return await Task.FromResult(new
                 {
                     msg = ex.ToString()
                 });
             }
     }
     return null;
 }
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:27,代码来源:ApiController.cs

示例4: Invoke

        public override Task Invoke(IOwinContext context)
        {
            //如果已经登录
            if (context.GetSession().ContainsKey(LOGINED_USER_KEY))
            {
                context.Environment[LOGINED_USER_KEY] = context.GetSession()[LOGINED_USER_KEY];
                return Next.Invoke(context);
            }

            var req = context.Request;
            var sourceRequestPath = req.Get<String>("Quick.OwinMVC.SourceRequestPath");
            if (sourceRequestPath == null)
                sourceRequestPath = req.Get<String>("owin.RequestPath");
            //如果是登录页面,则允许访问
            if (allowPaths.Contains(sourceRequestPath))
                return Next.Invoke(context);
            else
            //否则
            {
                //如果是API访问,则返回带错误信息的JSON数据
                var strs = sourceRequestPath.Split(new Char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                if (strs.Length > 2 && strs[1] == "api")
                {
                    var rep = context.Response;
                    var result = ApiResult.Error(-1, "当前未登录!").ToString();
                    rep.ContentType = "text/json; charset=UTF-8";
                    byte[] content = encoding.GetBytes(result);
                    rep.ContentLength = content.Length;
                    return context.Response.WriteAsync(content);
                }
                //跳转到登录页面
                return Task.Factory.StartNew(() =>
                {
                    var rep = context.Response;
                    if (sourceRequestPath != null)
                        req.Set("owin.RequestPath", sourceRequestPath);
                    var returnUrl = req.Uri.PathAndQuery;
                    //对URL进行编码
                    returnUrl = System.Web.HttpUtility.UrlEncode(returnUrl);
                    var redirectUrl = $"{req.Get<String>("ContextPath")}{loginPath}?{RETURN_URL_KEY}={returnUrl}";
                    rep.Redirect(redirectUrl);
                });
            }
        }
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:44,代码来源:LoginMiddleware.cs

示例5: doPost

        protected override object doPost(IOwinContext context)
        {
            var req = context.Request;
            var session = context.GetSession();
            var formData = context.GetFormData();
            var arg_password = formData["password"];
            if (arg_password == null)
            {
                return null;
            }
            String arg_password_str = Encoding.UTF8.GetString(Convert.FromBase64String(arg_password));
            String[] args = arg_password_str.Split(':');
            var account = args[0].Trim();
            var password = args[1];

            if (Svn.ApiController.Instance.Check(account, password))
            {
                session[LoginMiddleware.LOGINED_USER_KEY] = account;
                return ApiResult.Success();
            }
            return ApiResult.Error(context.GetText(Texts.ERROR_USER_PASSWORD_INCORRECT));
        }
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:22,代码来源:LoginController.cs

示例6: doGet

        protected override object doGet(IOwinContext context)
        {
            switch (context.Request.Query["type"])
            {
                case "user":
                    return new
                    {
                        user = context.GetSession()[LoginMiddleware.LOGINED_USER_KEY]
                    };
                case "info":
                    return new
                    {
                        time = Convert.ToInt64(TimeUtils.GetTime(DateTime.Now)),
                        basic = new
                        {
                            computer_name,
                            os_name,
                            process_run_time = (DateTime.Now - Process.GetCurrentProcess().StartTime).ToString(@"dd\.hh\:mm\:ss")
                        }
                    };
                case "cpu":
                    return new
                    {
                        time = Convert.ToInt64(TimeUtils.GetTime(DateTime.Now)),
                        cpu = new
                        {
                            used = SystemInfoUtils.GetCpuUsage(),
                            temp = SystemInfoUtils.GetCpuTempature()
                        }
                    };
                case "memory":
                    return new
                    {
                        memory = new
                        {
                            total = SystemInfoUtils.GetTotalMemory(),
                            free = SystemInfoUtils.GetFreeMemory(),
                        }
                    };
                case "disk":
                    return System.IO.DriveInfo.GetDrives().Where(t => t.IsReady && t.TotalSize > 0).Select(t => new
                    {
                        name = t.Name,
                        totalSize = t.TotalSize,
                        totalSizeString = storageUnitStringConverting.GetString(t.TotalSize),
                        totalUsed = t.TotalSize - t.TotalFreeSpace,
                        totalUsedString = storageUnitStringConverting.GetString(t.TotalSize - t.TotalFreeSpace),
                        driveFormat = t.DriveFormat
                    });
                case "regex":
                    {
                        var content = "0.233081";
                        var regex = new System.Text.RegularExpressions.Regex(@"^\s*(?'value'.*?)\s*$");
                        var match = regex.Match(content);
                        if (match == null || !match.Success)
                            return null;
                        var value = match.Groups["value"].Value;
                        return new
                        {
                            value
                        };
                    }
                case "process":
                    {
                        var process = new Process();
                        var psi = process.StartInfo;
                        psi.FileName = "bash";
                        psi.Arguments = "-c \"grep 'cpu ' /proc/stat| awk '{value=($2+$4)*100/($2+$4+$5)} END {print value}'\"";

                        psi.UseShellExecute = false;
                        psi.RedirectStandardOutput = true;

                        process.Start();
                        var content = process.StandardOutput.ReadToEnd();
                        process.WaitForExit();

                        return new
                        {
                            content
                        };
                    }
            }
            return null;
        }
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:84,代码来源:IndexApiController.cs

示例7: doGet

 protected override object doGet(IOwinContext context)
 {
     var rep = context.Response;
     context.GetSession().Clear();
     return (ApiResult.Success());
 }
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:6,代码来源:LoginController.cs


注:本文中的IOwinContext.GetSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。