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


C# HttpListenerContext.Redirect方法代码示例

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


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

示例1: HandleRequest

        public bool HandleRequest(Client client, HttpListenerContext context, params string[] args)
        {
            this.context = context;

            if (client.Connected())
            {
                context.Redirect("../home");
                return true;
            }

            if (context.GetMethod() == HttpMethod.GET)
            {
                this.ShowRegister(client);
            }
            else if (context.GetMethod() == HttpMethod.POST)
            {
                Dictionary<string, string> requestData = context.GetData();

                if (requestData.ContainsKey("username") && requestData.ContainsKey("password"))
                {
                    string username = requestData["username"];
                    string password = PasswordManager.Hash(requestData["password"]);

                    User user = UserManager.CreateUser(username, password);
                    if (user != null)
                    {
                        if (UserManager.Login(username, requestData["password"], client))
                        {
                            context.Redirect("../home");
                            return true;
                        }
                    }
                    else
                    {
                        this.ShowRegister(client, new Error("Couldn't create the user!"));
                        return false;
                    }
                }

                this.ShowRegister(client, new Error("Something wrong happened there!"));
            }

            return true;
        }
开发者ID:MathieuMorrissette,项目名称:Simple-HTTP-Server,代码行数:44,代码来源:Register.cs

示例2: HandleRequest

        public bool HandleRequest(Client client, HttpListenerContext context, params string[] args)
        {
            this.context = context;

            if (client.Connected())
            {
                context.Redirect("../home");
                return true;
            }   

            if (context.GetMethod() == HttpMethod.GET)
            {
                this.ShowLogin(client);
            }
            else if(context.GetMethod() == HttpMethod.POST)
            {
                Dictionary<string, string> requestData = context.GetData();

                if (requestData.ContainsKey("username") && requestData.ContainsKey("password"))
                {
                    string username = requestData["username"];
                    string password = requestData["password"];

                    if (UserManager.Login(username, password, client))
                    {
                        context.Redirect("../home");
                    }
                    else
                    {
                        this.ShowLogin(client, new Error("Invalid username or password"));
                    }
                }
                else
                {
                    this.ShowLogin(client, new Error("Error"));
                }
            }

            return true;
        }
开发者ID:MathieuMorrissette,项目名称:Simple-HTTP-Server,代码行数:40,代码来源:Login.cs

示例3: HandleRequest

        public bool HandleRequest(Client client, HttpListenerContext context, params string[] args)
        {
            if (!UserManager.Connected(client))
            {
                context.Redirect("../login");
                return true;
            }

            User user = UserManager.GetUser(UserManager.GetUserID(client));

            Home_Template template = new Home_Template(user);
            context.Send(template.Render());

            return true;
        }
开发者ID:MathieuMorrissette,项目名称:Simple-HTTP-Server,代码行数:15,代码来源:Home.cs


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