Exemplo n.º 1
0
        public RootModule()
        {
            //   This will run as Synchronize but we can see the flags for async methodologies.
            Get["/pages/"] = (parameters) =>
            {
                var env = this.Context.GetOwinEnvironment();

                var requestBody        = (Stream)env["owin.RequestBody"];
                var requestHeaders     = (IDictionary <string, string[]>)env["owin.RequestHeaders"];
                var requestMethod      = (string)env["owin.RequestMethod"];
                var requestPath        = (string)env["owin.RequestPath"];
                var requestPathBase    = (string)env["owin.RequestPathBase"];
                var requestProtocol    = (string)env["owin.RequestProtocol"];
                var requestQueryString = (string)env["owin.RequestQueryString"];
                var requestScheme      = (string)env["owin.RequestScheme"];

                var responseBody    = (Stream)env["owin.ResponseBody"];
                var responseHeaders = (IDictionary <string, string[]>)env["owin.ResponseHeaders"];

                var owinVersion       = (string)env["owin.Version"];
                var cancellationToken = (CancellationToken)env["owin.CallCancelled"];

                var uri = (string)env["owin.RequestScheme"] + "://" + requestHeaders["Host"].First() +
                          (string)env["owin.RequestPathBase"] + (string)env["owin.RequestPath"];

                if (env["owin.RequestQueryString"].ToString() != "")
                {
                    uri += "?" + (string)env["owin.RequestQueryString"];
                }
                var x     = string.Format("{0} {1}", requestMethod, uri);
                var model = new NancyDemoModel()
                {
                    Id = "tas", Test = "NOOOOOO"
                };
                return(View["Index.cshtml", model]);
            };

            Post["/pages", true] = async(parameters, ct) =>
            {
                string link = await GetData(ct);

                var model = new NancyDemoModel()
                {
                    Id = "test", Test = link
                };
                return(View["Index", model]);
            };
        }
Exemplo n.º 2
0
        public HomeModule()
        {
            Get["/Home"] = _ =>
            {
                try
                {
                    this.RequiresAuthentication();
                    var model = new NancyDemoModel()
                    {
                        Id = "tas", Test = "NOOOOOO"
                    };

                    return(View["Home.cshtml", model]);
                }
                catch (Exception ex)
                {
                    Logger.Log.InfoFormat("Authorization: Home: {0}", ex.Message);
                    return(Response.AsRedirect("/pages"));
                }
            };
        }