httpcontext

HttpContext.Current not Resolving in MVC 4 Project

旧街凉风 提交于 2019-12-18 12:05:29
问题 I am wanting to use ImageResizer (from ImageResizing dot net). I installed ImageResizer for MVC via NuGet. But when I go to use the following code from the example: //Loop through each uploaded file foreach (string fileKey in HttpContext.Current.Request.Files.Keys) { HttpPostedFile file = HttpContext.Current.Request.Files[fileKey]; if (file.ContentLength <= 0) continue; //Skip unused file controls. //The resizing settings can specify any of 30 commands.. See http://imageresizing.net for

How to use Rhino Mocks to Mock an HttpContext.Application

走远了吗. 提交于 2019-12-18 11:43:28
问题 I'm new to Mocking frameworks and have started using RhinoMocks to assist with my MVC App Unit Testing. I'm using Scott Hanselmanns MVC Mock Helper to assist in mocking the HttpContext. I've succesfully (after some time) mocked some of what I need but have come unstuck when it comes to the Application property of the HttpContext. In my application I store an object in the Application and retrieve it within a Controller like: SomeObj foo = (SomeObj)Application["fooKey"]; This gets created on

Where to use Controller.HttpContext

☆樱花仙子☆ 提交于 2019-12-18 07:26:25
问题 In my base controller's constructor I am calling an extension method that checks for specific cookies on the client. Currently I am using System.Web.HttpContext.Current to get the current context. However, I am lead to believe that I should be using Controller.HttpContext since it is more testable and contains additional information about the request. However, Controller.HttpContext returns null on creation (believe this is by design) but also on Initialize and Execute methods (unless I use

HttpContext.Current is null in my web service

别等时光非礼了梦想. 提交于 2019-12-18 04:31:35
问题 I have a web service (.svc), and I am trying to capture the SOAP request using a piece of code found elsewhere on StackOverflow. The problem is that HttpContext.Current is null, so I can't access Request.InputString . Why is this null, and how can it be solved? XmlDocument xmlSoapRequest = new XmlDocument(); Stream receiveStream = HttpContext.Current.Request.InputStream; receiveStream.Position = 0; using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) {

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

别来无恙 提交于 2019-12-18 03:05:12
问题 What is the difference between these 2 piece of codes. HttpContext.Current.Session["myvariable"] Session["myvariable"] asp.net 4.0 and C# 4.0 回答1: 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

What is the meaning of thread-agility in ASP.Net?

孤人 提交于 2019-12-17 07:38:25
问题 I am reading an article about HttpContext and CallContext and see thread-agility. What does it mean? 回答1: It means that IIS is free to use more than one thread to handle a single request, although not in parallel. Basically, IIS tries to perform I/O operations asynchronously, thus freeing the calling thread for the duration of the operation. That thread is returned to the pool and can be used to handle other requests in the meantime. When the asynchronous I/O operation completes, control can

Using HttpContext.Current in WebApi is dangerous because of async

亡梦爱人 提交于 2019-12-17 04:45:13
问题 My question is a bit related to this: WebApi equivalent for HttpContext.Items with Dependency Injection. We want to inject a class using HttpContext.Current in WebApi area using Ninject. My concern is, this could be very dangerous , as in WebApi ( everything? ) is async. Please correct me if I am wrong in these points, this is what I investigated so far: HttpContext.Current gets the current context by Thread (I looked into the implementation directly). Using HttpContext.Current inside of

Access HttpContext.Current from different threads

假装没事ソ 提交于 2019-12-17 04:21:58
问题 I have a C# ASP.NET application which starts about 25 different threads running some methods in a class called SiteCrawler.cs. In HttpContext.Current.Session I want to save the result of the search made by the user and present it to the user when all the threads are finished running. My problem is that the HttpContext.Current object is null in the spawned threads because it doesn't exist there. What other options do I have to save user/session specific data without using session because of

Serializing HttpContext object to store in a database

∥☆過路亽.° 提交于 2019-12-14 02:43:42
问题 We have a C# ASP.Net MVC website. I would like to store everything contained in the HttpContext.Current.Request object in a table in SQL Server for later analysis. I attempted serializing the object into a Byte Array, then storing it in a binary field in SQL Server, however the serializer won't serialize the HttpContext object since it is not marked Serializable . Is there any way to mark a System.Web class as serializable? Or is there another way to accomplish this? 回答1: For production code,

Mocking HttpContext (Session)

痴心易碎 提交于 2019-12-13 19:39:36
问题 I've read many articles and blogs about mocking in mvc... Many of them were helpful, but i still have some problems: One such issue is that I need to use Session in My ActionResult, but in my Tests i get a NullReferenceException when Session is accessed. public ActionResult Index() { if (Session["Something"] == null) { Session.Add("Something", <smth>); } else { Session["Something"] = <smth>; } return redirect to action("Index2"); } My test look like this: HomeController controller = new