httpcontext

HttpContext.Current.Response inside a static method

I have the following static method inside a static class. My question is it safe to use HttpContext.Current.Response inside a static method? I want to be 100% sure that it is thread safe and is only associated with the calling thread.. Does anybody know the answer? public static void SetCookie(string cookieName, string cookieVal, Syste...

how can i redirect the page with AJAX??

I am using Infragistics control in my application. If the user get deleted from my application then i want to redirect that user to not authorize page. for redirection of the page i am using HttpContext method but it's not working. I tried windows.location as well through java script but it's not working as well. Can somebody help me how...

Type-safe alternative to HttpContext.Items

I am implementing an HTTP Module in ASP.NET to identify geographical information based on the request's IP (a GeoIP module) and I will need to place things somewhere so the handler or later modules can inspect. Except HttpContext.Items (which is not type-safe) is there some other decent alternative? ...

Is it possible to set a page specific cookie?

I know it is possible to set a cookie for a path such as "/" or "/folder/", but is it possible to set a cookie for a specific page, such as "/folder/page.html"? ...

ASP.NET MVC - Generate Routes Without Http/Request Context

I'd like to be able to generate URLs from a RouteCollection without having access to the HttpContext. Looking at the way RouteCollection is implemented, all methods require access to a RequestContext in order to get the virtual path. I've worked around this by mocking the HttpContext but this adds an awkward dependency on RhinoMocks an...

Asynchronous HttpWebRequests and a null HttpContext.Current.Response/Request object.

I have a web application the relies heavily on web services. Everything with the services is done asynchronously and with AddOnPreRequestHandlerExecuteAsync. Anyhow, most of my calls work just fine, but some are returning from their asynchronous service calls to find a null HttpContext.Current.Response/Request object in the endprerequest...

How do I get an `HttpContext` object from `HttpContextBase` in ASP.NET MVC 1?

I'm working with some WebForms/MVC-agnostic tools, and I need to get an instance of HttpContext given a reference to an HttpContextBase object. I can't use HttpContext.Current because I need this to work asynchronously as well (HttpContext.Current returns null during an asynchronous request). I'm aware of HttpContextWrapper, but goes the...

HttpContext causing an Object reference error only in IIS 7

I recently set up a new instance of my personal website on the same server as the actual site. The new instance is a "latest" configuration so it's got all the new features of the latest build I'm working on. The latest build I've switched the Target Framework to 3.5 from 2.0 as the only really major change as fas as the compiled items g...

elmah: exceptions without HttpContext?

I spawn a thread on Application_Start and would like to log exceptions. There is not Context/HttpContext/HttpContext.Current, so how might i get it to log? ATM it does not catch any exception in my threads and if i write ErrorSignal.FromCurrentContext().Raise(ex); i get an error about context cannot be null. Maybe i can create a dummy ...

how do you capture httpcontext user information in your controller code when using visual studio

i asked this question which allowed me to capture user by using: string userName = this.HttpContext.User.Identity.Name; in my controller code. One issue i have is that when testing in visual studio it shows up as an empty string. I want to track this field for my testing. Is there anyway to have this work in the local ASP.net web...

Get host name without using HttpRequest

I'm want to run a "background job" in my ASP.NET application (periodically, as separate thread). And I need host name (DNS name or IP) to do my tasks. The problem - HttpContext.Current may be not available here (it's NULL). Is there any way to get a host name in not using HttpContext.Current.Request.Url.Host. ...

Application_PreRequestHandlerExecute: null HttpContext.Current?

Is it safe to always assume that HttpContext.Current will be non-null in Application_PreRequestHandlerExecute? EDIT: Assuming ASP.NET webforms (not MVC). ...

Asynchronous HTTP Handler and using HttpContext in a background thread?

I was reading Walkthrough: Creating an Asynchronous HTTP Handler and noticed they pass the HttpContext from the handler thread and use it in a WaitCallback which runs on a background thread. It makes calls like _context.Response.Write(). Am I correct in assuming that this doesn't violate the fact that HttpContext is not thread safe bec...

HttpContext Items Not Available to Web Method Called by AJAX

I have an item that I store in the HttpContext: HttpContext.Current.Items["myItem"] = "123"; I can access this no problem from any of a page's methods. For example: protected override void OnLoad(EventArgs e) { string l_myItemVal = HttpContext.Current.Items["myItem"] as string; // "123" } This works fine. However, when callin...

ASP.NET MVC : How to create own HttpContext

Hello .NET gurus, My idea was to create my own HttpContext which will include some of the internal objects used in our app. So I thought I will simply create public class FooHttpContextBase : HttpContextBase { public string Foo { get { return "Boo"; } } } And then override HttpContext property: public abstract c...

Problem with Commerce Server and ASP.NET Integrated Pipeline

I am using Microsoft Commerce Server 2007 and a custom ASP.NET 2.0 website. Everything works well in Classic Pipeline, but when I try to use the Integrated pipeline, it fails with the following error: Server Error in '/' Application. Request is not available in this context Description: An unhandled exception occurred duri...

Using HttpContext.Current.CurrentHandler for runtime view access

Is there any potential pitfall for using HttpContext.Current.CurrentHandler for runtime view access? public static GetView<T>(T view) where T : IView { return HttpContext.Current.CurrentHandler as T; } ...

Using MapPath from a worker thread

Hi, I have a WCF service method that's running in a worker thread I spin from another method. I need to map a relative service app path ("~/Templates/a.template") to the physical path ("D:\Web\Templates\a.template"), but I can't use HttpContext.Current.Server.MapPath because HttpContext.Current is null in a worker thread. How else can I...

Entity Framework Object Context in ASP.NET Session object?

Hi there, We have a multi-layered Asp.NET Web Forms application. The data layer has a class called DataAccess which impements IDisposable and has an instance of our Entity Framework Object Context as a private field. The class has a number of public methods returning various collections of Entities and will dispose its Object Context wh...

Why is HttpContext.Current NULL when using an ASP.NET ReportViewer and an ObjectDataSource?

Hi there, I have an ASP.NET Web Forms app using Entity Framework in the data layer. I've recently changed the app over to use one Object Context per request as per this post. It works great for the entire application except for any page which uses a ReportViewer to display something. I've noticed that it fails when trying to get an in...