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


C# IApplicationBuilder.UseSession方法代码示例

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


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

示例1: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseSession();

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:djhaley,项目名称:InputScrubbingModelBinder,代码行数:27,代码来源:Startup.cs

示例2: Configure

        public void Configure(IApplicationBuilder app)
        {
            app.UseSession();

            app.Map("/session", subApp =>
            {
                subApp.Run(async context =>
                {
                    int visits = 0;
                    visits = context.Session.GetInt32("visits") ?? 0;
                    context.Session.SetInt32("visits", ++visits);
                    await context.Response.WriteAsync("Counting: You have visited our page this many times: " + visits);
                });
            });

            app.Run(async context =>
            {
                int visits = 0;
                visits = context.Session.GetInt32("visits") ?? 0;
                await context.Response.WriteAsync("<html><body>");
                if (visits == 0)
                {
                    await context.Response.WriteAsync("Your session has not been established.<br>");
                    await context.Response.WriteAsync(DateTime.Now + "<br>");
                    await context.Response.WriteAsync("<a href=\"/session\">Establish session</a>.<br>");
                }
                else
                {
                    context.Session.SetInt32("visits", ++visits);
                    await context.Response.WriteAsync("Your session was located, you've visited the site this many times: " + visits);
                }
                await context.Response.WriteAsync("</body></html>");
            });
        }
开发者ID:yaobos,项目名称:Session,代码行数:34,代码来源:Startup.cs

示例3: Configure

        // Configure is called after ConfigureServices is called.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseErrorPage(ErrorPageOptions.ShowAll);
                app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
            }
            else
            {
                app.UseErrorHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseIdentity();
            app.UseSession();

            // Add authentication middleware to the request pipeline. You can configure options such as Id and Secret in the ConfigureServices method.
            // For more information see http://go.microsoft.com/fwlink/?LinkID=532715
            // app.UseFacebookAuthentication();
            // app.UseGoogleAuthentication();
            // app.UseMicrosoftAccountAuthentication();
            // app.UseTwitterAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:writeline,项目名称:Lockr,代码行数:35,代码来源:Startup.cs

示例4: Configure

        public void Configure(IApplicationBuilder app)
        {
            app.UseStaticFiles();

            app.UseIdentity();

            app.UseSession();

            app.UseMvc(routes =>
            {
                //routes.MapRoute(
                //    name: "leaveComment",
                //    template: "Blog/LeaveComment",
                //    defaults: new { controller = "Blog", action = "LeaveComment" });

                routes.MapRoute(
                    name: "findPostById",
                    template: "Blog/{id}",
                    defaults: new { controller = "Blog", action = "ViewPost" });

                routes.MapRoute(
                    name: "tagged",
                    template: "Blog/Tagged/{tag}",
                    defaults: new { controller = "Blog", action = "Tagged" });

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

            });
        }
开发者ID:gwartnes,项目名称:Blogness,代码行数:31,代码来源:Startup.cs

示例5: Configure

        public void Configure(IApplicationBuilder app)
        {
            // Configure Session.
            app.UseSession();

            // Add static files to the request pipeline
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline
            app.UseIdentity();

            // Add login providers (Microsoft/AzureAD/Google/etc).  This must be done after `app.UseIdentity()`
            app.AddLoginProviders(new ConfigurationLoginProviders(Configuration.GetSection("Authentication")));

            // Add MVC to the request pipeline
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "areaRoute",
                    template: "{area:exists}/{controller}/{action}",
                    defaults: new { action = "Index" });

                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                routes.MapRoute(
                    name: "api",
                    template: "{controller}/{id?}");
            });

            //Populates the PartsUnlimited sample data
            SampleData.InitializePartsUnlimitedDatabaseAsync(app.ApplicationServices).Wait();
        }
开发者ID:Ranireddy,项目名称:PartsUnlimited,代码行数:35,代码来源:Startup.cs

示例6: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
                app.UseErrorPage();
            }
            else
            {
                //TODO: custom error page
                //app.UseErrorHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseSession();
            app.Use((context, next) =>
            {
                context.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
                context.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "*" });
                context.Response.Headers.Add("Access-Control-Allow-Methods", new[] { "*" });
                return next();
            });
            app.UseCookieAuthentication(options =>
            {
                options.AutomaticAuthentication = true;
            });
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });
            });
            app.UseSignalR();
        }
开发者ID:ScottKaye,项目名称:kreport-web,代码行数:35,代码来源:Startup.cs

示例7: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                //开发环境异常处理
                app.UseDeveloperExceptionPage();
            }
            else
            {
                //生产环境异常处理
                app.UseExceptionHandler("/Shared/Error");
            }
            //使用静态文件
            app.UseStaticFiles();
            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(Directory.GetCurrentDirectory())
            });

            //Session
            app.UseSession();
            //使用Mvc,设置默认路由为系统登录
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Login}/{action=Index}/{id?}");
            });

            SeedData.Initialize(app.ApplicationServices); //初始化数据
        }
开发者ID:Fonour,项目名称:Fonour,代码行数:34,代码来源:Startup.cs

示例8: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment environment)
        {
            Console.WriteLine("Startup:Configure");
            try
            {
                app.UseDeveloperExceptionPage();
                app.UseCors("AllowAll");
                //app.UseWelcomePage();
                // Add the platform handler to the request pipeline.
                app.UseIISPlatformHandler();
                // Configure the HTTP request pipeline.
                app.UseStaticFiles();
                app.UseSession();
                app.UseMvc();
                //app.Run(async (context) =>
                //{
                //    await context.Response.WriteAsync("Hello World!");
                //});

                //Already earliest time to init as DbContext Services required to setup at ConfigureServices() first
                OriginChecker.Init(app.ApplicationServices);
                FileManager.Init(Configuration["FileManager:FullWebRoot"],
                    Path.Combine(environment.WebRootPath, Configuration["FileManager:RepositoryRootFolderName"])
                    //(PhotoManagementDb) app.ApplicationServices.GetService(typeof (PhotoManagementDb))
                    );
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error:{e.Message}\nAt:{e.Source}\nStack:{e.StackTrace}");
                Console.ReadLine();
            }
        }
开发者ID:ferrywlto,项目名称:PhotoManWebApi,代码行数:32,代码来源:Startup.cs

示例9: Configure

 public void Configure(IApplicationBuilder app)
 {
     app.UseStaticFiles();
     app.Use(next => new TimeRecorderMiddleware(next).Invoke);
     app.UseSession();
     app.UseMvc(Router.Instance.Route);
 }
开发者ID:simple0812,项目名称:YHCSheng,代码行数:7,代码来源:Startup.cs

示例10: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseIISPlatformHandler();

            app.UseStaticFiles();

            app.UseSession();
            app.UseMvc(routes =>
            {
                routes.MapRoute(null, "CC/{Component}", new {controller = "Home", action = "Index"});

                routes.MapRoute(null, "Angular/{Component}/{ViewName}",
                    new {controller = "Angular", action = "Template"});

                routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
            });

            new BaseDbInitialization(app.ApplicationServices.GetService<ICredicCardService>())
                .Init();
        }
开发者ID:IgorButenko,项目名称:ATM,代码行数:34,代码来源:Startup.cs

示例11: ConfigureAuth

        public void ConfigureAuth(IApplicationBuilder app)
        {
            // Populate AzureAd Configuration Values
            Authority = String.Format(Configuration.Get("AzureAd:AadInstance"), Configuration.Get("AzureAd:Tenant"));
            ClientId = Configuration.Get("AzureAd:ClientId");
            AppKey = Configuration.Get("AzureAd:AppKey");
            TodoListResourceId = Configuration.Get("AzureAd:TodoListResourceId");
            TodoListBaseAddress = Configuration.Get("AzureAd:TodoListBaseAddress");
            GraphResourceId = Configuration.Get("AzureAd:GraphResourceId");

            // Configure the Session Middleware, Used for Storing Tokens
            app.UseSession();

            // Configure OpenId Connect Authentication Middleware
            app.UseCookieAuthentication(options => { });
            app.UseOpenIdConnectAuthentication(options =>
            {
                options.ClientId = Configuration.Get("AzureAd:ClientId");
                options.Authority = Authority;
                options.PostLogoutRedirectUri = Configuration.Get("AzureAd:PostLogoutRedirectUri");
                options.Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    AuthorizationCodeReceived = OnAuthorizationCodeReceived,
                    AuthenticationFailed = OnAuthenticationFailed
                };
            });
        }
开发者ID:vansonvinhuni,项目名称:active-directory-dotnet-webapp-webapi-openidconnect-aspnet5,代码行数:27,代码来源:Startup.Auth.cs

示例12: Configure

 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(IApplicationBuilder app)
 {
     app.UseSession();
     app.UseStaticFiles();
     app.UseDeveloperExceptionPage();
     app.UseMvcWithDefaultRoute();
 }
开发者ID:MrXtry,项目名称:LabState,代码行数:8,代码来源:Startup.cs

示例13: Configure

        /// <summary>
        /// 設定AspNetCore
        /// </summary>
        /// <param name="app">應用程式建構器</param>
        /// <param name="env">環境變數</param>
        /// <param name="loggerFactory">記錄檔處理類別</param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            #region Development Configure
            //加入記錄主控台設定
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));

            //除錯模式
            loggerFactory.AddDebug();
            #endregion

            #region StaticFiles Configure
            //設定預設檔案
            ConfigureDefaultFiles(app);

            if (!env.IsDevelopment()) {//是否為開發模式
                app.UseDeveloperExceptionPage();//使用開發模式錯誤頁面
                app.UseDatabaseErrorPage();//使用資料庫錯誤頁面
                app.UseBrowserLink();//使用瀏覽器連結
            } else {
                ConfigureErrorPages(app, env);//設定錯誤頁面對應
            }

            //使用靜態檔案
            app.UseStaticFiles();
            #endregion

            //使用Session
            app.UseSession();

            //使用MVC服務,並且載入預設路由設定
            app.UseMvc(ConfigureMvcRoute);

            //WebSocket設定
            app.UseWebSockets<TestChatHanlder>();
        }
开发者ID:XuPeiYao,项目名称:AspNetCoreTemplate,代码行数:41,代码来源:Startup.cs

示例14: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole((category, level) =>
            {
                if (category.StartsWith("Microsoft."))
                {
                    return level >= LogLevel.Information;
                }

                return level >= LogLevel.Verbose;
            });

            app.UseStatusCodePages();
            app.UseFileServer();

            app.UseRequestLocalization(new RequestCulture("en-US"));

            app.UseSession();
            app.UseMvc(routes =>
            {
                routes.MapRoute("areaRoute", "{area:exists}/{controller}/{action}");
                routes.MapRoute(
                    "controllerActionRoute",
                    "{controller}/{action}",
                    new { controller = "Home", action = "Index" },
                    constraints: null,
                    dataTokens: new { NameSpace = "default" });

                routes.MapRoute(
                    "controllerRoute",
                    "{controller}",
                    new { controller = "Home" });
            });
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:34,代码来源:Startup.cs

示例15: Configure

 public void Configure(IApplicationBuilder app)
 {
     app.UseStaticFiles();
     //app.UseViewExports();
     app.UseSession();
     app.UseMvc();
 }
开发者ID:tuespetre,项目名称:html-mvc-aspnet5,代码行数:7,代码来源:Startup.cs


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