httpcontext

HttpContext on instances of Controllers are null in ASP.net MVC

喜你入骨 提交于 2019-11-28 04:58:56
This may not be the correct way to use controllers, but I did notice this problem and hadn't figured out a way to correct it. public JsonResult SomeControllerAction() { //The current method has the HttpContext just fine bool currentIsNotNull = (this.HttpContext == null); //which is false //creating a new instance of another controller SomeOtherController controller = new SomeOtherController(); bool isNull = (controller.HttpContext == null); // which is true //The actual HttpContext is fine in both bool notNull = (System.Web.HttpContext.Current == null); // which is false } I've noticed that

Is there an equivalent to “HttpContext.Response.Write” in Asp.Net Core 2?

守給你的承諾、 提交于 2019-11-28 01:03:47
问题 I'm trying to append some HTML and Javascript content on page using ActionFilter in Asp.Net Core 2. In MVC, it's working with filterContext.HttpContext.Response.Write(stringBuilder.ToString()); but in Core it not working. I tried to implement with this: filterContext.HttpContext.Response.WriteAsync(stringBuilder.ToString()); But it make complete page to blank. I'm looking solution for nopCommerce 4.0 which build in Asp.Core 2.0 回答1: You can try something like this In a custom implementation

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

♀尐吖头ヾ 提交于 2019-11-28 00:49:26
问题 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

HttpContext.Items with ASP.NET MVC

旧城冷巷雨未停 提交于 2019-11-27 21:03:05
I'm implimenting my own ApplicationContext class that uses the singleton pattern. I want to store my instance of it in HttpContext.Items, since it is accessible in all parts of the request. I've been reading about using HttpContext with ASP.NET MVC and one of the major pains is that it introduces testing complexity. I've tried doing research on the testability of HttpContext.Items, but all I can find is stuff on Session. One of the only things I've found is out of a sample chapter in the Professional ASP.NET 3.5 MVC book on Wrox ( pdf link here ). On page 15 it says this: Something You Can’t

Request.UserHostAddress issue with return result “::1”

混江龙づ霸主 提交于 2019-11-27 20:58:51
I am trying to get client ip address using HttpContext.Request.UserHostAddress; but it returns ::1 . How to solve this? V4Vendetta ::1 is for localhost , Maybe this might be useful. This is not a bug - you're connecting from localhost on an IPv6 enabled machine. ::1 is the loopback address - a double colon means "omitted zeroes" , so this address corresponds to address 1. If you're developing new software, I'd urge you not to disable IPv6. The easiest time to implement support is right from the start, and spending time on workarounds is perhaps just wasting effort putting off the inevitable.

Correct way to use HttpContext.Current.User with async await

别来无恙 提交于 2019-11-27 20:25:27
I am working with async actions and use the HttpContext.Current.User like this public class UserService : IUserService { public ILocPrincipal Current { get { return HttpContext.Current.User as ILocPrincipal; } } } public class ChannelService : IDisposable { // In the service layer public ChannelService() : this(new Entities.LocDbContext(), new UserService()) { } public ChannelService(Entities.LocDbContext locDbContext, IUserService userService) { this.LocDbContext = locDbContext; this.UserService = userService; } public async Task<ViewModels.DisplayChannel> FindOrDefaultAsync(long id) { var

elmah: exceptions without HttpContext?

二次信任 提交于 2019-11-27 19:16:16
I spawn a thread on Application_Start and would like to log exceptions. There is no Context/HttpContext/HttpContext.Current , so how might I get it to log? At the moment, it does not catch any exception in my threads and if I write ErrorSignal.FromCurrentContext().Raise(ex); I get an error about context cannot be null. Maybe I can create a dummy HttpContext but somehow I don't think that will work well. -edit- I tried ErrorSignal.Get(new HttpApplication()).Raise(ex); and it doesn't seem to pick up that exception. Brendan Carey Make sure you set your application name in web.config <errorLog

access HttpContext.Current from WCF Web Service

痴心易碎 提交于 2019-11-27 18:22:14
I just started using WCF Services with ASP.NET AJAX. I instantiate my WCF service from Javascript and then pass string variables as arguments to my WCF Service method (with an OperationContract signature). I then return a .NET object (defined with a DataContract) which is bound to my custom Javascript class. I'm having trouble authenticating based on the user logged into my web session. However, the WCF web service is a completely different service with no context to the HttpContext.Current object. What is the most secure way to get access to that object? You can get access to HttpContext

How do I get an HttpContext object from HttpContextBase in ASP.NET MVC 1?

无人久伴 提交于 2019-11-27 17:33:05
I'm working with some WebForms/MVC-agnostic tools, and I need to get an instance of HttpContext given a reference to an HttpContextBase object. I can't use HttpContext.Current because I need this to work asynchronously as well ( HttpContext.Current returns null during an asynchronous request). I'm aware of HttpContextWrapper , but goes the wrong way. Atif Aziz The simplest way is to get the application, ApplicationInstance , and use its Context property: // httpContextBase is of type HttpContextBase HttpContext context = httpContextBase.ApplicationInstance.Context; (thanks to Ishmael Smyrnow

What is the WCF equivalent of HttpContext.Current.Request.RawUrl?

安稳与你 提交于 2019-11-27 11:31:59
问题 I've got some RESTful services running in a pure WCF context (i.e. ASP.NET compatibility is not enabled, and thus there is no HttpContext.Current object available). The URLs to the services are rewritten at the start of the request using an IHttpModule (which at that point does have an HttpContext and rewrites it using HttpContext.Current.RewritePath ) to get rid of things like the .svc extension from the URL. However, I need to access the original URL that was requested from within the WCF