httpcontext

What is the difference between HttpContext.Current.Response and Page.Response?

柔情痞子 提交于 2020-01-23 11:08:30
问题 I'm troubleshooting a caching issue on a set of secured pages and have realized that the Header needs to be modified for all Responses. As I put together a solution, I want to know the difference between HttpContext.Current.Response and Page.Response and when each object should be used in an app. Thanks. 回答1: Page.Response is simply a mapping to the HTTPContext when you are within the context of an HTML page. HttpContext.Current.Response simply allows you to get to the current context, when

What is the difference between HttpContext.Current.Response and Page.Response?

谁说胖子不能爱 提交于 2020-01-23 11:07:34
问题 I'm troubleshooting a caching issue on a set of secured pages and have realized that the Header needs to be modified for all Responses. As I put together a solution, I want to know the difference between HttpContext.Current.Response and Page.Response and when each object should be used in an app. Thanks. 回答1: Page.Response is simply a mapping to the HTTPContext when you are within the context of an HTML page. HttpContext.Current.Response simply allows you to get to the current context, when

Entity Framework ObjectContext with Dependency Injection

别说谁变了你拦得住时间么 提交于 2020-01-21 10:28:54
问题 Well, it seems like I'm stuck in my application structure. Here's what I want to do: UI layer: An ASP.NET webforms website. BLL: Business logic layer which calls the repositories on DAL. DAL: .EDMX file (Entity Model) and ObjectContext with Repository classes which abstract the CRUD operations for each entity. Entities: The POCO Entities. Persistence Ignorant. Generated by Microsoft's ADO.Net POCO Entity Generator. I'd like to create an obejctcontext per HttpContext in my repositories to

Entity Framework ObjectContext with Dependency Injection

Deadly 提交于 2020-01-21 10:28:45
问题 Well, it seems like I'm stuck in my application structure. Here's what I want to do: UI layer: An ASP.NET webforms website. BLL: Business logic layer which calls the repositories on DAL. DAL: .EDMX file (Entity Model) and ObjectContext with Repository classes which abstract the CRUD operations for each entity. Entities: The POCO Entities. Persistence Ignorant. Generated by Microsoft's ADO.Net POCO Entity Generator. I'd like to create an obejctcontext per HttpContext in my repositories to

MultipartFormDataStreamProvider and preserving current HttpContext

别说谁变了你拦得住时间么 提交于 2020-01-16 07:05:54
问题 I have a problem with the async file uploading feature of WebApi. Currently I am able to save the file using the provider, but I then want to use a service (_myService) to log the filename of the file uploaded. Inside the service, it uses another service to get the current UserId. It does this by using the current HttpContext. Unfortunately the current HttpContext seems to be lost within the new task thread. I tried to add TaskScheduler.FromCurrentSynchronizationContext() as the 2nd parameter

How to setup Request.Header in FakeHttpContext for Unit Testing

别等时光非礼了梦想. 提交于 2020-01-14 07:58:06
问题 I have a FakeHttpContext I have been trying to modify to include some headers for testing purposes public static HttpContext FakeHttpContext() { var httpRequest = new HttpRequest("", "http://stackoverflow/", ""); var stringWriter = new StringWriter(); var httpResponse = new HttpResponse(stringWriter); var httpContext = new HttpContext(httpRequest, httpResponse); var sessionContainer = new HttpSessionStateContainer("id", new SessionStateItemCollection(), new HttpStaticObjectsCollection(), 10,

Get ActionResult of another controller-action?

感情迁移 提交于 2020-01-13 16:32:20
问题 I want to store items in the application cache so it's lazy loaded from the main layout view. I also want to be able to invalidate the cache, so if it's invalid, next time when the items-collection is requested, it's reloaded to that cache location. Here's what I've implemented: In the controller: protected IEnumerable<Slide> CachedSlides { get { return HttpContext.Application[SlidesCacheKey] as IEnumerable<Slide>; } set { HttpContext.Application[SlidesCacheKey] = value; } } private void

Get host name without using HttpRequest

大憨熊 提交于 2020-01-13 08:46:14
问题 I 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 is that the 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 . 回答1: When the host name is available in HttpContext.Request.Url.Host , it is a result of the host name being part of the request sent by the client. As an example, take a

NHibernate thread safety with session

流过昼夜 提交于 2020-01-11 15:30:28
问题 I've been using NHibernate for a while now and have found from time to time that if I try to request two pages simultaniously (or as close as I can) it will occasionally error. So I assumed that it was because my Session management was not thread safe. I thought it was my class so I tried to use a different method from this blog post http://pwigle.wordpress.com/2008/11/21/nhibernate-session-handling-in-aspnet-the-easy-way/ however I still get the same issues. The actual error I am getting is:

Programmatically refresh/update HttpContext.User

北城以北 提交于 2020-01-11 05:59:59
问题 I'm using FormsAuthentication for an ASP.NET site that has a master page that displays the current logged in user, Page.User.Identity.Name. They can change their username in their settings, and when the do so, I update their cookie for them so they wont have to sign out/sign back in with a postback. FormsAuthentication.SignOut(); FormsAuthentication.SetAuthCookie(username, false); I'm probably being pretty nit-picky, but after they change their username the master page still displays their