Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpContext.Session.SetString #1577

Closed
FourLeafClover opened this issue Jun 17, 2016 · 3 comments
Closed

HttpContext.Session.SetString #1577

FourLeafClover opened this issue Jun 17, 2016 · 3 comments

Comments

@FourLeafClover
Copy link

FourLeafClover commented Jun 17, 2016

AspNet core rc2
package: Microsoft.AspNetCore.Session

    HttpContext.Session.SetString(key,value)   error.

I have add code in the startUp.cs.

        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services
            services.AddApplicationInsightsTelemetry(Configuration);
            services.AddAuthorization();
            services.AddSession(options =>
            {
                options.IdleTimeout = TimeSpan.FromDays(7);
                options.CookieName = ".FileSystem";
            });
            services.AddMvc();
        }
         public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            #region

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

            app.UseApplicationInsightsRequestTelemetry();

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

            app.UseApplicationInsightsExceptionTelemetry();

            app.UseStaticFiles();

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

            #endregion

            app.UseSession();
        }
    }

** Not working. HttpContext.session.setString()

error: Session has not been configured for this application or request.

I have read some blogs: asp.net core rc1.
The blogs shows that i should import the package: aspnet.session.
but when i import this package, the package can not support app.UseSession() function.

Help! how can i use session in aspNet core RC2

@pranavkm
Copy link
Contributor

Middlewares get added to the pipeline in the order in which they appear in your code. In this case, UseSession appears after UseMvc; consequently it isn't set up until after Mvc has executed. Add it at some point before your call to UseMvc. https://docs.asp.net/en/latest/fundamentals/middleware.html#creating-a-middleware-pipeline-with-iapplicationbuilder has pretty useful information as to how this works.

@FourLeafClover
Copy link
Author

@pranavkm Thanks very much.

@murat1922
Copy link

useless

natemcmaster pushed a commit that referenced this issue Nov 14, 2018
- The latest libuv package has a new linux RID that should
let us remove the work around with setting the RID
in the docker file and systemd service
@dotnet dotnet locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants