httpcontext

What is the difference between these two HttpContext.Current.Session and Session - asp.net 4.0

浪子不回头ぞ 提交于 2019-11-29 01:19:00
What is the difference between these 2 piece of codes. HttpContext.Current.Session["myvariable"] Session["myvariable"] asp.net 4.0 and C# 4.0 They're effectively the same, in that they will access the same Session data. The reason you can call Session in your code-behind is because ASP.Net pages by default extend the System.Web.UI.Page type. This has a Session public property. If you look at the code for this in Reflector you can see that it just calls HttpContext.Current.Session itself (through its own Context property). In other classes you will not have access to that property, but you can

What is the difference between these two HttpContext.Current.Session and Session - asp.net 4.0

无人久伴 提交于 2019-11-29 01:17:11
What is the difference between these 2 piece of codes. HttpContext.Current.Session["myvariable"] Session["myvariable"] asp.net 4.0 and C# 4.0 They're effectively the same, in that they will access the same Session data. The reason you can call Session in your code-behind is because ASP.Net pages by default extend the System.Web.UI.Page type. This has a Session public property. If you look at the code for this in Reflector you can see that it just calls HttpContext.Current.Session itself (through its own Context property). In other classes you will not have access to that property, but you can

How do I retrieve the HttpContext properties when it returns null?

流过昼夜 提交于 2019-11-29 00:46:18
问题 I am doing some asynchronous work on a separate thread using: ThreadPool.QueueUserWorkItem() and in this separate thread, I need to call HttpContext.Current so that I can access: HttpContext.Current.Cache HttpContext.Current.Server HttpContext.Current.Request However, HttpContext.Current is null when I create this separate thread. Question How do I create a new thread so that HttpContext.Current is not null? Or is there another way I can access the Cache, Server, and Request objects? 回答1: I'd

How to access the HttpServerUtility.MapPath method in a Thread or Timer?

▼魔方 西西 提交于 2019-11-28 17:16:48
问题 I use a System.Timers.Timer in my Asp.Net application and I need to use the HttpServerUtility.MapPath method which seems to be only available via HttpContext.Current.Server.MapPath . The problem is that HttpContext.Current is null when the Timer.Elapsed event fires. Is there another way to get a reference to a HttpServerUtility object ? I could inject it in my class' constructor. Is it safe ? How can I be sure it won't be Garbage Collected at the end of the current request? Thanks! 回答1: It's

accessing HttpContext.Request in a controller's constructor

守給你的承諾、 提交于 2019-11-28 16:58:02
I'm following this ASP.NET MVC tutorial from Microsoft : My code is slightly different, where I'm trying to access HttpContext.Request.IsAuthenticated in the controller's constructor. namespace SCE.Controllers.Application { public abstract class ApplicationController : Controller { public ApplicationController() { bool usuario = HttpContext.Request.IsAuthenticated; } } } The problem is that HttpContext is always null. Is there a solution to this? The Controller is instantiated significantly prior to the point where the Index action is invoked, and at the moment of construction HttpContext is

MVC5 Ninject binding and HttpContext

南楼画角 提交于 2019-11-28 12:51:38
I am trying to set up a new project and I've added a new class MembershipService that requires the HttpContext to be passed in it's constructor. In a previous project I used the code private static void RegisterServices(IKernel kernel) { kernel.Bind<IMembershipService>() .To<MembershipService>() .InRequestScope() .WithConstructorArgument("context", HttpContext.Current); .... } However in the new project I'm using Ninject Modules, and after some searching on StackOverflow and Google, I've come up with the code below: public class ServiceHandlerModule : NinjectModule { public override void Load(

Using an HTTPContext across threads

此生再无相见时 提交于 2019-11-28 12:00:49
User hits page spawn.aspx which then spawns a half-dozen threads, rendering pages all using ((System.Web.IHttpHandler)instance).ProcessRequest(reference to spawn's HTTPContext); Don't worry about the fact that ASP.Net is seemingly sending the user 7 responses for 1 request, that part is handled and only one response gets sent. The problem is, in a high-traffic enviroment (our Production enviroment) with many threads (quad-quads) we get an error: System.IndexOutOfRangeException at System.collections.ArrayList.Add at System.Web.ResponseDependencyList.AddDependencies(String[] items, String

How to access ServerVariables in AspnetCore 1.0

天涯浪子 提交于 2019-11-28 08:17:56
问题 In exisiting .Net Web Site, Server Variables is accessed using HttpContext.Current.Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"] How to access the ServerVariables in AspnetCore 1.0 Web Application? While debugging inside controller, this.HttpContext.Features does not contain IServerVariablesFeature . 回答1: Okay, I am not going to directly answer your question. I am going to try and throw some light on why this server variable is not a problem anymore. "HTTP_ACCEPT_LANGUAGE" is a server

Get application path without using httpcontext. (asp.net)

随声附和 提交于 2019-11-28 05:39:59
How to do it? I don't want to use this: HttpContext.Current.Server.MapPath Is there a similar function that I can call without requiring a httpcontext? For example if a start a thread doing some stuff i cant use the httpcontext, but i still need to get the path of the app. And no i can't pass the context as an argument or read it from a shared var. Use the HttpRuntime.AppDomainAppPath property. There are several options: HttpRuntime.AppDomainAppPath WebApplication -> Web root folder UnitTest -> ArgumentNullException ConsoleApplication -> ArgumentNullException AppDomain.CurrentDomain

Can we use Response.Flush () instead of Response.End()

故事扮演 提交于 2019-11-28 05:28:25
问题 Response.End() generates ThreadAbortException . Using HttpContext.Current.ApplicationInstance.CompleteRequest in place of it doesn't solve the problem. So, can we use Response.Flush() instead of Response.End() 回答1: The Response.Flush() is send to the browser what is on buffer, but is not stop the processing of the page, so it will continue the execution of the next steps. What is Response.End() do is to stop the execution steps on the next function call in the asp.net Page Life Cycle . http:/