Trong ASP.NET WebApi được lưu trữ trong IIS 7, nó có quyền truy cập vào phiên không? Nó xuất hiện Session
là null trên HttpContext.Current
.Phiên WebApi ASP.NET và Biến tĩnh
Sự khác nhau giữa hai loại này để lưu trữ biến toàn cầu là gì?
private static Dictionary<string, string> ConnectionStrings
{
get
{
if (HttpContext.Current.Session["ConnectionStrings"] == null)
HttpContext.Current.Session["ConnectionStrings"] = new Dictionary<string, string>();
return HttpContext.Current.Session["ConnectionStrings"] as Dictionary<string, string>;
}
}
và
private static Dictionary<string, string> connectionStrings = new Dictionary<string, string>();
Tôi có nên sử dụng phiên hoặc các biến tĩnh để lưu trữ các chuỗi kết nối được tự động tạo ra (câu chuyện dài)?