httpcontext

Does static reference to HttpContext.Current.Session return same session for all users?

我与影子孤独终老i 提交于 2020-01-11 03:10:07
问题 Is there room for issue in the following code in terms of multiple users of the same web application? I mean, I know that a purely static string will be shared across all sessions for a single ASP.NET application, but given that this explicitly refers to the Current.Session , even though it is static it seems like it would always refer to the session instance of the "current user." But an error is happening that could be explained by everyone sharing the current value of Mode and thus the

HttpContext on instances of Controllers are null in ASP.net MVC

旧街凉风 提交于 2020-01-09 08:51:05
问题 This may not be the correct way to use controllers, but I did notice this problem and hadn't figured out a way to correct it. public JsonResult SomeControllerAction() { //The current method has the HttpContext just fine bool currentIsNotNull = (this.HttpContext == null); //which is false //creating a new instance of another controller SomeOtherController controller = new SomeOtherController(); bool isNull = (controller.HttpContext == null); // which is true //The actual HttpContext is fine in

C# .net UriTemplate match url from a whitelist or pool or servers

↘锁芯ラ 提交于 2020-01-07 03:42:16
问题 You can use UriTemplate to parse the url: I have this code in which locally on localhost:29001 I set the host to be a specific Uri and then I check to if it is a Match In my real code I do have the the line var absoluteUri = HttpContext.Current.Request.Url.AbsoluteUri; of which is used like this var match = apiTemplate.Match(host, new Uri(absoluteUri)); but essentially this is what the code is going to look like in C# from it running. var host = new Uri("http://localhost:29001"); var

Server-side equivalent of HttpContext?

為{幸葍}努か 提交于 2020-01-04 06:30:02
问题 I have a web app that currently uses the current HttpContext to store a LINQ Data Context. The context is persisted for the current request, on a per user basis, per Rick Strahl's blog: string ocKey = "ocm_" + HttpContext.Current.GetHashCode().ToString("x") Thread.CurrentContext.ContextID.ToString(); if (!HttpContext.Current.Items.Contains(ocKey)) { // Get new Data Context and store it in the HTTP Context } However, I have some scripts that execute from the global.asax file, that don't have

Remove HttpContext.Current.Session

佐手、 提交于 2020-01-03 18:57:09
问题 I have an application which stores session variables. When I do the logout I call the RemoveAll() method on available sessions. The method seems not working. Do you know how it is possible to force removing a Session variable? Regards. 回答1: Session.Abandon() cancels the current session Session.Clear() will just clear the session data and the the session will remain alive more Details: Session.Abandon() method destroys all the objects stored in a Session object and releases their resources. If

Inheriting LINQ-to-SQL data context from base controller

瘦欲@ 提交于 2020-01-02 05:04:31
问题 My base controller class, BaseController , is inherited by public-facing controllers to access a shared data context between requests with LINQ-to-SQL. Am I accessing my data context in an efficient and safe way by storing it in HttpContext.Current.Items for each HTTP request? DataContextHelper class internal static class DataContextHelper { public static MyDataContext CurrentContext { get { if (HttpContext.Current.Items["MyDataContext"] == null) { MyDataContext context = new MyDataContext();

Mocking a HttpContext Response.Output with Moq

僤鯓⒐⒋嵵緔 提交于 2019-12-31 22:39:31
问题 I've been using the MvcMockHelpers class found at Hanselman's blog for passing in a mocked HttpContext. We extended it somewhat to add some authentication data we needed and for the most part this has been great. The issue we are having is that the context we are giving to the controller has a null value in the HttpContext.Response.Output, which is causing some exceptions to be thrown. I'm not sure what to add to get this working. Here is the existing FakeHttpConext() method: public static

What's the difference between the HttpRuntime Cache and the HttpContext Cache?

六眼飞鱼酱① 提交于 2019-12-31 09:17:29
问题 I know there is a very similar question here but I was hoping to get a better explination. Why would I ever use HttpContext.Cache instead of HttpRuntime.Cache if the HttpContext really uses the HttpRuntime.Cache behind the scenes? In the article Simulate a Windows Service using ASP.NET to run scheduled jobs Omar uses the HttpContext to store his cache items, but when Jeff Atwood Implemented it here he chose to use the HttpRuntime instead. Obviously in this particular situation it makes sense

What's the difference between the HttpRuntime Cache and the HttpContext Cache?

ぐ巨炮叔叔 提交于 2019-12-31 09:17:25
问题 I know there is a very similar question here but I was hoping to get a better explination. Why would I ever use HttpContext.Cache instead of HttpRuntime.Cache if the HttpContext really uses the HttpRuntime.Cache behind the scenes? In the article Simulate a Windows Service using ASP.NET to run scheduled jobs Omar uses the HttpContext to store his cache items, but when Jeff Atwood Implemented it here he chose to use the HttpRuntime instead. Obviously in this particular situation it makes sense

Castle.Windsor and HttpContextWrapper

时光毁灭记忆、已成空白 提交于 2019-12-30 12:17:51
问题 HttpContextWrapper and HttpContextBase, as explained here, were introduced to make HttpContext more mockable/testable. I'm trying to use it with S#arp Architecture, and hitting some problems. My MVC Controllers are set up to accept an HttpContextBase argument in the constructor, and during Application_Start, HttpContextBase is registered with Castle.Windor as follows: container.Register(Component.For<HttpContextBase>().UsingFactoryMethod( () => new HttpContextWrapper(HttpContext.Current)));