httpcontext

HttpContext.Current not Resolving in MVC 4 Project

荒凉一梦 提交于 2019-11-30 06:05:53
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 details. //Destination paths can have variables like <guid> and <ext>, or //even a santizied version of the

How to use Rhino Mocks to Mock an HttpContext.Application

我是研究僧i 提交于 2019-11-30 04:02:13
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 Application_Start in my MVC App. UPDATED FOLLOWING FIRST ANSWER (additional code for clarity) Currently

How to access the HttpServerUtility.MapPath method in a Thread or Timer?

会有一股神秘感。 提交于 2019-11-29 21:10:02
I use a System.Timers.Timer in my Asp.Net application and I need to use the HttpServerUtility.MapPath method which seems to be only available via HttpContext.Current.Server.MapPath . The problem is that HttpContext.Current is null when the Timer.Elapsed event fires. Is there another way to get a reference to a HttpServerUtility object ? I could inject it in my class' constructor. Is it safe ? How can I be sure it won't be Garbage Collected at the end of the current request? Thanks! Costo It's possible to use HostingEnvironment.MapPath() instead of HttpContext.Current.Server.MapPath() I haven't

HttpContext.Current null inside async task

最后都变了- 提交于 2019-11-29 17:55:31
问题 I have a method that uses a repository ( userRepo ): public override Task<IdentityResult> CreateLocalUserAsync(IUser user, string password, CancellationToken cancellationToken) { var task = new Task<IdentityResult>(() => { TUserEntity newUser = new TUserEntity { Id = user.Id, UserName = user.UserName, Password = password }; userRepo.Save(newUser).Flush(); return new IdentityResult(true); }, cancellationToken); task.Start(); return task; } The userRepo object has a dependency that uses

HttpContext.Current.Response inside a static method

烂漫一生 提交于 2019-11-29 17:02:39
问题 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, System.TimeSpan ts) { try { HttpCookie cookie = new HttpCookie(CookiePrefix + cookieName) {Value = cookieVal, Expires = DateTime.Now.Add(ts)}; HttpContext.Current

How to access ServerVariables in AspnetCore 1.0

送分小仙女□ 提交于 2019-11-29 14:37:17
In exisiting .Net Web Site, Server Variables is accessed using HttpContext.Current.Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"] How to access the ServerVariables in AspnetCore 1.0 Web Application? While debugging inside controller, this.HttpContext.Features does not contain IServerVariablesFeature . Okay, I am not going to directly answer your question. I am going to try and throw some light on why this server variable is not a problem anymore. "HTTP_ACCEPT_LANGUAGE" is a server variable that IIS & .NET used to facilitate on ASP.NET framework to communicate content language with the

Where to use Controller.HttpContext

99封情书 提交于 2019-11-29 13:11:13
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 Routing.RequestContext.HttpContext?). So if I should be using Controller.HttpContext instead of

StructureMap is not disposing data context when using HttpContextScoped()

家住魔仙堡 提交于 2019-11-29 13:04:37
问题 My goal is to have one data context ( MainDbContext ) per HTTP request in ASP.NET MVC and dispose the data context when the request ends. I'm using the following StructureMap configuration: public static class ContainerConfigurer { public static void Configure() { ObjectFactory.Initialize(x => { x.For<MainDbContext>().HttpContextScoped(); }); } } Whenever I need a MainDbContext , I'm using this code: var dbContext = ObjectFactory.GetInstance<MainDbContext>(); This is working as expected: only

“System.Web.HttpContext cannot be serialized because it does not have a parameterless constructor.”

空扰寡人 提交于 2019-11-29 07:16:51
I've created a web service that other sites can use to store errors in my database. They can then come to my site to view their errors, search through errors, filter errors, etc. However, I'm getting the following error for my web service: System.Web.HttpContext cannot be serialized because it does not have a parameterless constructor. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: System.Web

HttpContext.Current is null in my web service

放肆的年华 提交于 2019-11-29 05:33:24
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)) { xmlSoapRequest.Load(readStream); } If you want to use HttpContext because the code has already been written as so;