w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
HttpContext.Current.Items after an Async operation
Cutting a long story short, it normally should. Unless you are using ConfigureAwait(false) which can have a side effect with continuation not flowing the context. Alternatively try adding this setting in your app. <appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> </appSettings> UPDATE NOTE!! Initially I put false. But it must be true so that context flows.

Categories : C#

Is HttpContext.Current.Items thread-safe between Requests?
HttpContext Encapsulates all HTTP-specific information about an individual HTTP request. Hence each request HttpContext.Items["sameKey"] will be a different copy.

Categories : C#

Viability of referencing ASP.NET Web Controls from the HttpContext.Items collection?
An ASP.NET Page is also an HTTP Handler through IHttpHandler interface implementation and therefore is a valid candidate to use with the HttpContext.Items collection by definition in the MSDN document. Because Page Controls are effectively in a handler there seems no apparent risk to reference page controls from the Items collection. My main concern was lifetime of control objects in context of the Page versus longer lifetime of the request/context the collection relates to. However Controls will still be disposed properly through IDisposable when the page is complete and the garbage collector will still clean up Controls when they are finally released from the Items collection which shouldn't be long after the page handler expires.

Categories : Asp Net

Find key using lambda expression in HttpContext.Current.Items cache
The Items property is an IDictionary, so you'd have to do this: public IEnumerable<string> GetKey (Func<string, bool> condition) { return HttpContext.Current.Items .Cast<DictionaryEntry>() .Where(e => e.Key is string && e.Value is string && condition(e.Key as string)) .Select(e => e.Value as string); } or in query syntax: public IEnumerable<string> GetKey (Func<string, bool> condition) { return from e in HttpContext.Current.Items.Cast<DictionaryEntry>() where e.Key is string && e.Value is string && condition(e.Key as string) select e.Value as string; } Update I miss-read the question

Categories : C#

.NET 4.0 MVC load error, what the hell is this?
I figured it out. I was also using a custom compression attribute I had forgotten about (thanks, @Steve) which I presume was clashing with the Ombres settings, or at the very least, not decompressing properly. I removed those attributes anyway and the normal error pages turned up, which coincidentally related to Combres.

Categories : Asp Net Mvc

ASP.Net Assembly version hell
I stay away from this world by: Changing the folder structure to this: .MySolution.sln .MyFirstProjectMyFirstProject.csproj .MySecondProjectMySecondProject.csproj .MyThirdProjectMyThirdProject.csproj .MyOtherProjectSomeFolderMyOtherProject.csproj .ThirdPartyReferences Put all of your referenced assemblies in ".ThirdPartyReferences". Have all the csproj reference the .dll's using the "..ThirdPartyReferencesMyCoolDll.dll" (however many ".." you need) The every csproj has to use the same version and originating location of any third party references.

Categories : C#

Callback hell in nodejs?
Yes you are in callback hell. The solution assuming you don't want to use async (which I doubt you can justify other than prejudice) consists of: 1) Make more top-level functions. Each function should perform either 1 or 2 IO operations as a rule of thumb. 2) Call those functions, making your code follow a pattern of a long list of short core functions organized into business logic by a small list of control flow "glue" functions. Instead of: saveDb1 //lots of code saveDb2 //lots of code sendEmail //lots of code Aim for: function saveDb1(arg1, arg2, callback) {//top-level code} function saveDb2(arg1, arg2, callback) {//top-level code} function sendEmail(arg1, arg2, callback) {//top-level code} function businessLogic(){//uses the above to get the work done} 3) Use more functi

Categories : Node Js

R on Windows: character encoding hell
According to Wikipedia: The byte order mark (BOM) is a Unicode character used to signal the endianness (byte order) [...] The Unicode Standard permits the BOM in UTF-8, but does not require nor recommend its use. Anyway in the Windows world UTF8 is used with BOM. For example the standard Notepad editor uses the BOM when saving as UTF-8. Many applications born in a Linux world (including LaTex, e.g. when using the inputenc package with the utf8) show problems in reading BOM-UTF-8 files. Notepad++ is a typical option to convert from encoding types, Linux/DOS/Mac line endings and removing BOM. As we know that the UTF-8 non-recommended representation of the BOM is the byte sequence 0xEF,0xBB,0xBF at the start of the text stream, why not removing it with R itself? ## Conv

Categories : R

MySQLi Transaction Spaghetti Hell
One option might be to delete: $this->connection->autocommit(FALSE); $this->connection->commit(); in every function that is relevant (a,b) and then wrap them around your function calls. class MyClass { private $connection = ...; // mysqli connection public function a () { // do something and run multiple queries } public function b () { // do something and run multiple queries $this->a(); // running function a inside function b here } } // to run the code: $myclass = new MyClass(); $myclass->connection->autocommit(FALSE); $myclass->a(); // all queries are run inside a transaction $myclass->b(); $this->connection->commit(); UPDATE: OR maybe better , use a wrapper-function for calling the functions inside t

Categories : PHP

Symbol parsing hell in Java
It looks like an encoding problem. Your application uses one encoding, while the server uses other. Using the Charset class will be your answer. Use it when converting received data to String. Most probably you'll have to specify it in a Reader constructor, though I can't say without any code. Here is the link to appropriate javadoc: InputStreamReader(InputStream, Charset)

Categories : Java

Checkbox hell - webmatrix/razor
You have a WHERE clause in your INSERT statement which makes no sense. If you are inserting, you create a new row. I suspect you intend to UPDATE an existing row in which case your SQL should be: "UPDATE PropertyInfo SET FePool = @0, FeJac= @1, FeGames = @2 WHERE PropertyID=@3" If a checkbox is not checked, nothing will be included for that checkbox in the Request.Form collection. If it is checked, the value passed is "on" by default, or whatever you have specified in the "value" attribute. For check1, that will be "true". For check2, that will be "check2". You need to establish whether the checkbox was actually included in the Request.Form collection and then set the values you want to commit to the database accordingly. If you want to pass true or false depending on whether the checkb

Categories : SQL

Android Holoeverywhere Proguard hell
The error is in SystemServiceManager.java of Holoeverywhere. If you read the code you'll noticed that it is intentionally throwing the error as something is going wrong with annotations public static void register(Class<? extends SystemServiceCreator<?>> clazz) { if (!clazz.isAnnotationPresent(SystemService.class)) { throw new RuntimeException( "SystemServiceCreator must be implement SystemService"); } SystemService systemService = clazz.getAnnotation(SystemService.class); final String name = systemService.value(); if (name == null || name.length() == 0) { throw new RuntimeException("SystemService has incorrect name"); } MAP.put(name, clazz); } A check of the proguard troubleshooting document shows that by default i

Categories : Java

Alternatives/Tools for #define hell C/C++
In case all your #define's are in a single configuration file, you can try doing a preprocessor-only compilation and then finding all defined macros. E.g., $ gcc -DFEATURE1 -DFEATURE2 -E configuration.h | grep '#define'

Categories : C++

Haskell Platform + Cabal hell + packages location?
Why those packages installed in those locations? /usr/local/lib/ghc-7.6.3 contains libraries that come with ghc. And /usr/local/lib contains libraries from "haskell platform" How do i delete the whole cabal packages for reinstall? Use ghc-pkg to unregister libraries in /usr/local/lib. It is better not to do that with libraries /usr/local/lib/ghc-7.6.3 Which installation options allow me to put all cabal packages into a single folder? AFAIK there are no such option (not tutorial intended) Is it better to learn to solve the cabal hell? I've heard about ghc-pkg After the new constrains solver was introduced in cabal, the cabal hell almost disappeared for me. The last cabal-install release introduced sandboxes, and other improvements coming. I hope the cabal hell will di

Categories : Haskell

NuGet to manage versioning of internal assemblies - DLL Hell
There's no real magic bullet to this one. Either the developers have to take some responsibility for ensuring changes to shared assemblies don't impact other code that references those assemblies or you really shouldn't be sharing them across projects. If the things they're changing in these shared assemblies really happens that often, you might consider migrating those parts or the methods they're changing to each individual project. Sharing assemblies like this should really only be done for absolute core functions that should change very, very infrequently.

Categories : C#

Parent Last Classloader to solve Java Class path hell?
Ok, you created your own classloader and then loaded a class using it. The question is - how does the thread classloader will know about that? So, you must load the class using some classloader, and then set this classloader as thread context classloader.

Categories : Java

Strategy for Understanding Eclipse bundles and plug-ins / Escape from dependency hell
You could try to add the binary jar to your local eclipse plugins directory. You can find it here.

Categories : Eclipse

Will loading my app from Eclipse to my Android phone instead of AVD will speed things up? Because AVD is slow as hell
Very simply said, it absolutely will. Enable USB debugging on your device. Install phone drivers and connect your phone to your PC. When running your application choose your phone from the list and run. Read more about all steps on Using Hardware Devices, Android developer site

Categories : Android

Moqing HttpContext
If you are using premium or above version of vs2012, try looking at microsoft.fakes. it should cater to your situation. Some reading: http://msdn.microsoft.com/en-us/library/hh549175.aspx

Categories : Asp Net

SqlConnection and HttpContext
I wonder why you need to store a single SqlConnection. It doesn't smell great. If you really do need to share a single SqlConnection across multiple classes, dependency injection is likely a better option. Have a connection factory instantiate a connection object and pass it around as required. Otherwise, let the DBMS worry about controlling your connection resources. Create, open and close a connection each time you need one.

Categories : C#

Fake HttpContext? (ASP.NET MVC)
I was able to make it work using RazorEngine by removing all @Html tags from the partial view file. string template = System.IO.File.ReadAllText(path); string partialView = RazorEngine.Razor.Parse(template, model, "cachename"); http://forums.asp.net/t/1923611.aspx/2/10?Fake+HttpContext+ASP+NET+MVC+#5459457

Categories : Asp Net Mvc

HttpContext.Response.Filter
After a long digging around I noticed that VS2013 come with a new addition; SignalR - which as it turns out is associated with the ArteryFilter problem. So, in order to solve this problem, uncheck the "Enable Browser Link" feature next to your Debug button and voila; filters works as expected again. Still weird that VS2013 does not chain filters. Also, note that this is a general ASP.NET feature and hence not limited to MVC. PRESERVED FOR HISTORY - ANSWER IS ABOVE I am experiencing the same thing but so far it seems related to the new IISExpress and not VS2013 perse. What worked fine in VS2012 suffers the same fate as the one introduced by installing VS2013. When executed through normal IIS the problem disappears, hence your code is working fine. Let me know if you find a way to dis

Categories : Asp Net

Need httpcontext value in business layer
Using the HttpContext object to pass a global object is a bad idea. Normally, the business layer shouldn't even have a reference to System.Web. Resharper has the "Extract Class from Parameters ..." refactoring to automate what you describe. You can access it by right-clicking on your method's name and choose Refactor > Extract > Extract Class from Parameters. You can then select the parameters you want to include in the class. Resharper will update all references to the method to create and use the new class. In any case, more than 3 or 4 parameters is a code smell that suggests the method may be trying to do too many things. When you cross that threshold it's time to change your design and either consolidate the parameters or split the method.

Categories : C#

Can not access to HttpContext.Current
Have you included the System.Web assembly in the application? using System.Web; If not, try specifying the System.Web namespace, for example: System.Web.HttpContext.Current

Categories : C#

Getting Around HttpContext.Current issue
if (System.Environment.MachineName == "xxx") Although, the preferred way of doing that is to have a base web.config file, and creating XLST transforms for your different environments that change the values based on how you publish your project. For example, we have web.config, web.release.config, web.debug.config, and web.staging.config. We have different values for caching, output caching, the debug attribute, connection strings, email server settings, etc for each environment and they all get swapped out at publish time. Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application is started Select Case LCase(System.Environment.MachineName) Case "localhost", "development_domain" DB_Environment = "DEVELOPMENT" C

Categories : Dotnet

MultipartFormDataStreamProvider vs HttpContext.Current
This is what I found on MSDN. I think this might help you. The stream provider looks at the Content-Disposition header field and determines an output Stream based on the presence of a filename parameter. If a filename parameter is present in the Content-Disposition header field then the body part is written to a FileStream, otherwise it is written to a MemoryStream. This makes it convenient to process MIME Multipart HTML Form data which is a combination of form data and file content.

Categories : Dotnet

HttpContext.Current is null for bots
You should check the Session for null like so: public static bool BrowserSupportsJS { get { if(HttpContext.Current.Session == null) return false; return (HttpContext.Current.Session["js_support"] != null && ((bool)HttpContext.Current.Session["js_support"])); } }

Categories : C#

Is this a safe way to get body of a HttpContext request
I've needed use InputStream of Http Request. I have a WebApp and IOS App that navigates to a aspx page, if the url request contains some parameters i read the information in database and if i not find any parameters in url request i read the request body and i work fine ! protected void Page_Load(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(Request.QueryString["AdHoc"]) == false) { string v_AdHocParam = Request.QueryString["AdHoc"]; string [] v_ListParam = v_AdHocParam.Split(new char[] {','}); if (v_ListParam.Length < 2) { DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer

Categories : C#

use of timer causes HttpContext.Current to be null
HttpContext.Current only gives you the context you want when you call it on the thread that handles the incoming thread. When calling it outside of such threads, you get null. That matches your case, as Timer1_Elapsed is executed on a new thread.

Categories : Asp Net

HttpContext.Request.RawUrl and localhost
You can get what you want like this: string applicationPath = filterContext.HttpContext.Request.ApplicationPath; string returnUrl = filterContext.HttpContext.Request.RawUrl.Replace(applicationPath, "");

Categories : Asp Net Mvc

HttpContext.Current is null in Application_PreSendRequestHeaders
Did you recently upgrade from VS 2008 to VS 2012? I think you still need to upgrade the web.config file then. 1) Remove this section in the <configSections>: <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefin

Categories : C#

Why is HttpContext.Current null after await?
Is my test flawed, or is there some web.config element I'm missing here that would make HttpContext.Current resolve correctly after an await? Your test is not flawed and HttpContext.Current should not be null after the await because in ASP.NET Web API when you await, this will ensure that the code that follows this await is passed the correct HttpContext that was present before the await.

Categories : C#

HttpContext.Current Null in CacheItemUpdateCallback
Basically you have to create an ajax poll that calls a method that queries the cache object. You cannot update a page from a cache expiration callback as the thread that is used has nothing to do with a request object (it is part of the asp.net/iis process and not anything to do with a HttpRequest (which is where the .Context is populated)). So basically on the page you need to display the data create either a $.ajax or use an asp.net ATLAS timer (or straight .js ajax if you wish) that calls either a asmx endpoint or a WebMethod which can query the HttpContext.Current.Cache and return the appropriate string/html/json/xml/whatever data. UPDATE: There are libraries available for the server updating clients without the programmer understanding/implementing long polling/ polling techniques.

Categories : C#

Get AD Guid from HttpContext.Current.User
If you're on .NET 3.5 and up, you should check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace. Read all about it here: Managing Directory Security Principals in the .NET Framework 3.5 MSDN docs on System.DirectoryServices.AccountManagement Basically, you can define a domain context and easily find users and/or groups in AD: // set up domain context using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain)) { // find a user UserPrincipal user = UserPrincipal.FindByIdentity(ctx, User.Identity.Name); if(user != null) { Guid userGuid = user.Guid ?? Guid.Empty; } } The new S.DS.AM makes it really easy to play around with users and groups in AD!

Categories : Asp Net Mvc

HttpContext.Current.Cache VS. SQL Table Performance
What you are describing is really : duplicating the data into a second (technically redundant) model, more suitable for query. If that is the case, then sure : have fun with that - that isn't exactly uncommon. However, before doing all that, you might want to try indexed views - it could be that this solves most everything without you having to write all the maintenance code. I would suggest, however, not to "remove caching" - but simply "make the cache expire at some point"; there's an important difference. Hitting the database for the same data on every single request is not a great idea.

Categories : Sql Server

HttpContext.Current.Request.Form checkbox
The cbxR1, cbxR2 should be the name of an input element, not the id. <form ...> <input type="checkbox" name="cbxR1" checked="checked" /> <input type="checkbox" name="cbxR2" checked="checked" /> </form>

Categories : C#

HttpContext.Current is NULL in NServiceBus MessageMutator
MutateIncoming will be called on an NServiceBus worker thread and not on an ASP.NET worker thread - hence no HTTP context. Think of it - what would you expect the HTTP context to be when you're handling an NServiceBus message? If you need something from the user's session, you'd probably need to pass some kind of session ID or correlation ID around, allowing you leave the data in the right place when the reply message gets handled.

Categories : C#

Creating an HttpContext in MVC/StructureMap project running as a non-web app
To do as you suggest: For<RequestContext>().Use(ctx => { //TODO: Create unittest.html as required. SimpleWorkerRequest request = new SimpleWorkerRequest("/unittest", @"c:inetpubwwwrootunittest", "unittest.html", null, new StringWriter()); HttpContext context = new HttpContext(request); return HttpContext.Current = context; }); As was recommended though, abstracting the dependency upon the context would be a better long way to go.

Categories : C#

Find specific value in HttpContext.Current.Cache
You are getting this error because the object which you are trying to iterate does not implement IEnumerable interface. It seems like en.Value is an object here (I don't have VS with me to test it right now). If it is then, you need to cast it into the appropriate type and if your cast type is a collection and does not implement IEnumerable interface, you need to call AsEnumerable() extension method by System.Linq in place. Otherwise, as I said casting it into appropriate type should work.

Categories : Dotnet

Why HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath is different on different servers?
It gets the virtual path of the application root and makes it relative by using the tilde (~) notation. It does not says anything about the parameters of the path that you passed throught. If you look at the begining of the returned string, it is the same. I'm pretty sure that the URL in each request is different, with and without LoginUser, so the complete returned string seems different base on that, althought, for the function, they are the same.

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.