httpcontext

ASP.NET HttpContext.Current inside Task.Run

时光毁灭记忆、已成空白 提交于 2019-12-21 03:46:23
问题 I have a following code example that is used in ASP.NET MVC application. The purpose of this code is to create "fire and forget" request for queuing some long running operation. public JsonResult SomeAction() { HttpContext ctx = HttpContext.Current; Task.Run(() => { HttpContext.Current = ctx; //Other long running code here. }); return Json("{ 'status': 'Work Queued' }"); } I know this is not a good way for handling HttpContext.Current in asynchronous code, but currently our implementation not

Navigate to a new page and display an alert box

北城余情 提交于 2019-12-20 04:25:10
问题 I am developing an application by using ASP.Net WebForm. Once user click a button, application will navigate to a new page and prompt out a dialog box "Welcome to JackiesGame" However, I able to navigate to new page but the alert dialog box does not display. The following is my sample code void cmdCancel_Click(object sender, EventArgs e) { HttpContext.Current.Response.Redirect(Globals.NavigateURL(TabId), true); Page page2 = HttpContext.Current.CurrentHandler as Page; ScriptManager

Navigate to a new page and display an alert box

怎甘沉沦 提交于 2019-12-20 04:25:03
问题 I am developing an application by using ASP.Net WebForm. Once user click a button, application will navigate to a new page and prompt out a dialog box "Welcome to JackiesGame" However, I able to navigate to new page but the alert dialog box does not display. The following is my sample code void cmdCancel_Click(object sender, EventArgs e) { HttpContext.Current.Response.Redirect(Globals.NavigateURL(TabId), true); Page page2 = HttpContext.Current.CurrentHandler as Page; ScriptManager

How is HttpContext being maintained over request-response

风格不统一 提交于 2019-12-20 04:23:45
问题 I am wondering how the HttpContext is maintained given that the request-response nature of the web is essentially stateless. Is an identifier being for the HttpContext object being sent as part of the __EVENTTarget / __EVENTARGUMENTS hidden fields so that the HttpRuntime class can create the HttpContext class by reading this section from the request (HttpWorkerRequest)? I don't think Please let me know as I am trying to fill some holes in my understanding of the http pipeline and I was unable

Artificially populate HttpContext object in a Console application

≡放荡痞女 提交于 2019-12-20 04:21:07
问题 I am writing a wrapper library for log4net. This library should be able to capture Context information such as querystring, cookie, form fields etc. etc. I am invoking this wrapper class from Console application as opposed to TDD class. Is there a way to populate HttpContext object inside a Console application as follows? HttpContext c = new HttpContext(null); c.Request.QueryString.Keys[1] = "city"; c.Request.QueryString[1] = "Los Angeles"; c.Request.QueryString.Keys[2] = "state"; c.Request

In MVC3, how to get the current action name?

瘦欲@ 提交于 2019-12-19 07:40:35
问题 Is there a way to use HttpContext or the View context to get the current action name? I can get the controller name using var routeValues = HttpContext.Current.Request.RequestContext.RouteData.Values; if (routeValues != null) { if (routeValues.ContainsKey("controller")) { controllerName = HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString(); } } } 回答1: var routeValues = HttpContext.Current.Request.RequestContext.RouteData.Values; if (routeValues != null) { if

How to mock httpcontext so that it is not null from a unit test?

两盒软妹~` 提交于 2019-12-19 03:37:20
问题 I am writing a unit test and the controller method is throwing an exception because HttpContext / ControllerContext is null. I don't need to assert anything from the HttpContext, just need it to be not NULL. I have done research and I believe Moq is the answer. But all the samples that I have seen haven't helped me a lot. I don't need to do anything fancy, just to mock the httpcontext. Point me in the right direction! 回答1: Got these two functions from here in a class; public static class

Unified static class between HttpContext and SignalR HubCallerContext

南楼画角 提交于 2019-12-18 14:48:11
问题 I have a lot of code that depends on HttpContext.Current, and I noticed that requests that come from SignalR hubs have HttpContext.Current == null , so my code breaks, for example: HttpContext.Current.Request.IsAuthenticated So I came up with following: public static class UnifiedHttpContext { private static HubCallerContext SignalRContext { get; set; } private static int SignalRUserId { get { return WebSecurity.GetUserId(SignalRContext.User.Identity.Name); } } private static bool

Simple Injector: how to inject HttpContext?

谁说胖子不能爱 提交于 2019-12-18 13:20:11
问题 I have started using Simple Injector as my DI container (mostly for performance reason: if somebody has suggestions, please let me know) but some of the classes I wrote use HttpContextBase as constructor parameter. I have resolved for now removing it from the constructor and creating a Property, something like this: public HttpContextBase HttpContext { get { if (null == _httpContext) _httpContext = new HttpContextWrapper(System.Web.HttpContext.Current); return _httpContext; } set {

Entity Framework Object Context in ASP.NET Session object?

瘦欲@ 提交于 2019-12-18 12:38:58
问题 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 when it is disposed. Due to a number of problems we've been facing, we decided it would be a big plus to keep the Object Context (or an instance of DataAccess ) in scope