How can I disable session state in ASP.NET MVC?

后端 未结 5 1054
闹比i
闹比i 2020-11-27 11:42

I would like to have a very lightweight ASP.NET MVC site which includes removing as many of the usual HttpModules as possible and disabling session state. However when I try

5条回答
  •  没有蜡笔的小新
    2020-11-27 12:01

    I've found one way, which I don't particularly care for:

    Create NoTempDataProvider

    using System;
    using System.Collections.Generic;
    using System.Web.Mvc;
    
    namespace Facebook.Sites.Desktop.Auth.Models
    {
        public class NoTempDataProvider : ITempDataProvider
        {
            #region [ ITempDataProvider Members ]
    
            public IDictionary LoadTempData(ControllerContext controllerContext)
            {
                return new Dictionary();
            }
    
            public void SaveTempData(ControllerContext controllerContext, IDictionary values) { }
    
            #endregion
        }
    }
    

    Manually Overwrite the Provider in the Controller

    public class AuthController : Controller
    {
        public AuthController()
        {
            this.TempDataProvider = new NoTempDataProvider();
        }
    }
    

    I would greatly prefer a way to do this completely via the configuration, but this works for now.

提交回复
热议问题