示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseStatusCodePages();
            }

            app.UseSession();

            app.Run(async context => {
                RequstEntryCollection collection = GetOrCreatEntries(context);
                if (collection.TotalCount() == 0)
                {
                    await context.Response.WriteAsync("<html><body>");
                    await context.Response.WriteAsync("Your session has not been established.<br>");
                    await context.Response.WriteAsync(DateTime.Now.ToString() + "<br>");
                    await context.Response.WriteAsync("<a href=\"/session\">Established session</a><br>");
                }
                else
                {
                    collection.RecordRequest(context.Request.PathBase + context.Request.Path);
                    //SaveEntrise(context, collection);
                    //.............未完待续...............
                }
            });
        }
示例#2
0
        private RequstEntryCollection GetOrCreatEntries(HttpContext context)
        {
            RequstEntryCollection collection = null;

            byte[] requestEntriesBytes = context.Session.Get("RequestEntries");
            if (requestEntriesBytes != null && requestEntriesBytes.Length > 0)
            {
                string json = System.Text.Encoding.UTF8.GetString(requestEntriesBytes);
                return(JsonConvert.DeserializeObject <RequstEntryCollection>(json));
            }

            if (collection == null)
            {
                collection = new RequstEntryCollection();
            }

            return(collection);
        }