für einen Komponententest Ich versuche, dem HttpApplicationState-Objekt einen Wert hinzuzufügen, der die Application-Eigenschaft der HttpContext.Current-Klasse ist. Ich versuche, mit dem folgenden Code.NET, wie das HttpContext-Objekt fehlzuschlagen
TextWriter tw = new StringWriter();
HttpWorkerRequest wr = new SimpleWorkerRequest("/webapp", @"path...", "logon.asp", "", tw);
HttpContext.Current = new HttpContext(wr);
//I try the following 2 lines
HttpContext.Current.Application["KeyValue"] = "myValue";
HttpContext.Current.Application.Add("KeyValue", "myValue");
var count = HttpContext.Current.Application.Count;
var get1 = HttpContext.Current.Application["KeyValue"];
var get2 = HttpContext.Current.Application.Get("KeyValue");
Aber HttpContext.Current.Application.Count ist immer Null. Die Werte werden nicht
Was mache ich falsch?
mit .NET Framework 3.5 tatsächlich. Diese Klassen sind für .NET 4 – Bob
ok. Sie existieren auch in 3.5. – bluevoodoo1
ah du bist korrekt. Immer noch Probleme, es funktioniert zu bekommen. HttpContext erbt nicht von HttpContextBase, so dass ich meine eigene Klasse nicht erstellen und stattdessen verwenden kann oder fehlt mir irgendetwas? – Bob