httpcontext

What is the performance impact of tracing in C# and ASP.NET?

霸气de小男生 提交于 2019-12-04 00:39:39
I found this in some production login code I was looking at recently... HttpContext.Current.Trace.Write(query + ": " + username + ", " + password)); ...where query is a short SQL query to grab matching users. Does this have any sort of performance impact? I assume its very small. Also, what is the purpose of this exact type of trace, using the HTTP Context? Where does this data get traced to? Thanks in advance! JaredPar Yes it will have a performance impact whenever the TRACE conditional compilation constant is defined during build. Doing anything has some type of impact :) As to whether or

ASP.NET HttpContext.Current inside Task.Run

大兔子大兔子 提交于 2019-12-04 00:32:09
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 allows us to do something else. I would like to understand how much this code is dangerous... The

Determine the URL hostname without using HttpContext.Current?

99封情书 提交于 2019-12-03 23:30:27
Using the current request I can get the URL hostname with: HttpContext.Current.Request.Url.Host But - I need to determine the URL hostname without using the current request ( HttpContext.Current ). The reason for this is that my code is called from a SqlDependency in the onChange callback for when a SQL Dependency is found. Althougth the code resides in my web app, there is no request, and HttpContext.Current is null. I was hoping I could grab it from HttpRuntime , but there doesn't seem to be anything of use there. is there a way I can get this information? If you know the host at the moment

MVC, not “supposed” to use HttpContext.Current anymore?

ε祈祈猫儿з 提交于 2019-12-03 19:30:42
问题 Someone in a post here, commented that you should not use HttpContext.Current when using MVC, rather, you should be using ControllerBase.ControllerContext. In some respects, this makes sense, but in other respects it doesn't. For example, ControllerContext is an instance variable, so everywhere I want to reference, say, my Session variables, I need to have a reference to the Controller? Why are we "not supposed" to be using HttpContext.Current in MVC, when you still can? Is there an

Read Http Request into Byte array

余生颓废 提交于 2019-12-03 14:31:23
问题 I'm developing a web page that needs to take an HTTP Post Request and read it into a byte array for further processing. I'm kind of stuck on how to do this, and I'm stumped on what is the best way to accomplish. Here is my code so far: public override void ProcessRequest(HttpContext curContext) { if (curContext != null) { int totalBytes = curContext.Request.TotalBytes; string encoding = curContext.Request.ContentEncoding.ToString(); int reqLength = curContext.Request.ContentLength; long

Injecting HttpContext in Ninject 2

天大地大妈咪最大 提交于 2019-12-03 12:36:26
问题 In my asp.net mvc application I'm using Ninject as a DI framework. My HttpAccountService is used by my controllers to get info from and to cookies. For this I need the HttpContext.Current in the HttpAccountService. As this is a dependency I injected it throught the constructor as such: kernel.Bind<IAccountService>() .To<HttpAccountService>() .InRequestScope() .WithConstructorArgument("context", HttpContext.Current); Sadly this always binds to the same context which makes that after the first

Can I fool HttpRequest.Current.Request.IsLocal?

可紊 提交于 2019-12-03 12:13:40
I'm running a web application that displays some debugging behavior if it's being run locally - quotes around resource strings, etc - and I'd like to demo the application on my laptop at a conference where I won't have internet access, so it has to be local. The application uses HttpContext.Current.Request.IsLocal to determine if it's running locally - is there any way to fool it? I'd like to trick it into returning "False" even though I am indeed running locally. I do have access to the source code (and realize I could just demo a build where the "IsLocal" check is commented out), but would

Get/Set HttpContext Session Methods in BaseController vs Mocking HttpContextBase to create Get/Set methods

你说的曾经没有我的故事 提交于 2019-12-03 08:44:28
问题 I created Get/Set HttpContext Session Methods in BaseController class and also Mocked HttpContextBase and created Get/Set methods. Which is the best way to use it. HomeController : BaseController { var value1 = GetDataFromSession("key1") SetDataInSession("key2",(object)"key2Value"); Or var value2 = SessionWrapper.GetFromSession("key3"); GetFromSession.SetDataInSession("key4",(object)"key4Value"); } public class BaseController : Controller { public T GetDataFromSession<T>(string key) { return

Call the default asp.net HttpHandler from a custom handler

我的梦境 提交于 2019-12-03 07:28:27
问题 I'm adding ASP.NET routing to an older webforms app. I'm using a custom HttpHandler to process everything. In some situations I would like to map a particular path back to an aspx file, so I need to just pass control back to the default HttpHandler for asp.net. The closest I've gotten is this public void ProcessRequest(HttpContext context) { // .. when we decide to pass it on var handler = new System.Web.UI.Page(); handler.ProcessRequest(context); MemoryStream steam = new MemoryStream();

Request.Url.Host and ApplicationPath in one call

大兔子大兔子 提交于 2019-12-03 05:52:47
问题 Is there any way to get HttpContext.Current.Request.Url.Host and HttpContext.Current.Request.ApplicationPath in one call? Something like "full application url"? EDIT: Clarification - what I need is this the part within []: http://[www.mysite.com/mywebapp]/Pages/Default.aspx I ask simply out of curiosity. EDIT 2: Thanks for all the replies, but none of them were exactly what I was looking for. FYI, I solved the problem this way (but am still interested in knowing if there's a smoother way):