Reading & Writing to a Cookie Inside a HttpHandler
When you are working within an HttpHandler, sometimes you need to access or write out state information. Since this is wrapped up in a class and not inheriting from the Page class, we need to approach this in a slightly different manner. The ProcessRequest method within IHttpHandler has a Response object drawn from HttpContext. The functionality works the same, we just need to adjust how we reference the cookie as follows:
Writing out a Cookie Reading from the CookieDisplay Alternate Sidebar Based on Page in WordPress
I don’t know about you, but I get tired looking at that same right sidebar on every page of my WordPress sites. Not all pages are created equal, and some need to serve up different content based on where we are in the site. For my particular case, I wanted to display custom content to the last page in a checkout process. To do this we have to first determine which page we are on by looking at the $_SERVER['REQUEST_URL']. If we were on http://aspnetprogrammer.net/hello_world, it would return the value hello_world. Next, we set the queryValue of the page we are looking for then trigger our comparison. The strstr function in php compares two strings, telling us if the second is contained within the first. If it is, we display the checkout.php sidebar. Otherwise, we let the default sidebar load as normal.
Add Home Page Link to Menubar in WordPress Blog
It is about the most basic thing in the world to start a menu navigation bar with a link to your home page, but for some reason many nice WordPress templates seem to have overlooked this essential element. It will list out your categories fine, but no go on getting you back to the beginning. Let’s fix that oversight. In your header file under Appearance > Editor (this file may be called something different depending on the template you are using), we’re going to look for a line of code that looks like this:
That is where these category options are getting inserted. Now to append a link to the home page to the beginning of these links simply precede the above line with the following code:
WordPress Replacing Ampersands in Javascript
As great as WordPress is for running a blog, it comes with more than its fair share of headaches for the developers out there. Today, I was putting some javascript code into the body of my post. Whenever you get more clever than basic text and html in the body of a post, watch out! So WordPress started chewing up all my ampersands and replacing them with & and of course the javascript was rendered useless. I searched high and low for a fix and nothing. I know there has to be a config file somewhere in this WordPress install that replaces those ampersands. I’m sure its for XHTML compliance issue or something like that, but I want to be able to rid myself of this intrusion. So while I didn’t find a solution, I did find a work around that should have occured to me earlier — just wrap the javascript up in its own file and make a reference to it from the post body. It would look something like this:
The key here is, if WordPress can’t process the javascript directly, it can’t mangle your ampersands. F%$kin’ A man!
Tags: javascript, WordPressWordPress Running Slow on GoDaddy
I don’t know what it is, but for the past week all my blogs have been running dog slow on GoDaddy. All my other sites (ASP.NET based) run fine. I contacted support and I got the ever so unhelpful “this problem is something on your side” or my personal favorite “you need to upgrade your account to a dedicated server.” What? You can’t support a measly blog, and you want me to shell out major bucks for a dedicated server? Not happening. After doing some investigation on the web, nothing could be further from the truth. Many, many, many people are having these slow crawling load times when running WordPress on GoDaddy. The solution — find another web host. Seriously, out of the four web forums I scoured no one had run across a solution past jumping ship.
The one host that kept coming up time and again in my research was Bluehost. Even WordPress themselves had Bluehost listed first on their list of recommended web hosts. Everyone kept saying their support was great and load times were very quick. I just got setup yesterday with them, and I’m busy pulling over files and setting up databases. I’ll check back in to let you know how it goes.
Update [8/27/09]: One week on BlueHost, and I’m happy to confirm that all blogs are zipping right along. No delays, no unbearable load times, none of that Godaddy crap. The problem definitely wasn’t on my end. You’d think they’d be able to at least run a little WordPress blog. Guess I expect too much. As far as the transition over to BlueHost, it was fairly painless. Basically, you just export your mySQL database to a file comprised of a bunch of SQL statements. After creating the cooresponding database on your BlueHost mySQL account, you just import the SQL file and all your data is up. Then just download all your blog files and restore them to the new folder location you’ve setup for the site on BlueHost. Next you need to point the wp-config.php file to the new database as follows:
Your final step is just to go into your domain provider and point the DNS record to go to BlueHost. The DNS servers you are looking for are primary NS1.BLUEHOST.COM and backup NS2.BLUEHOST.COM. Then you just have to wait for the changes to propogate through the Internet’s hub routers. I’ve seen it take as quick as five minute to a couple of hours. No rhyme or reason to it. Whalah you’re setup and you’ve left Godaddy’s interminable crawl in the past.
Oh with regards to support, BlueHost was very responsive. I submitted 4 requests as I was getting setup and they were normally back to me within 30 minutes to an hour via email, and I didn’t get a single boneheaded answer that was cut and pasted out of the knowledgebase that had absolutely nothing to do with my issue. Of course that was the norm with Godaddy’s hosting support and many other hosts I’ve used in the past. Very satisfied so far with the whole hosting experience at BlueHost.
Tags: bluehost, goDaddy, WordPressSQL OUTER JOIN: The When, the Where & the How To
So I’m trucking along wrapping up a project, throwing in a few last minute testing changes and I put in a new textbox that isn’t like any other others. All the previous were connected up via the database with a store item. This button is more of an aggregator for checkboxes or radiobuttons. So the essential problem was, it wasn’t pulling back in my stored procedure since it didn’t have that store item associate with it. No problem. We’ll just employ our OUTER JOINs. As you no doubt know, JOINs or INNER JOINs connect up two database tables and only return the results that exists in both databases. OUTER JOINS aren’t quite as picky. It will bring back the results regardless whether its contained in both tables or not. It is going to have the following syntax:
Get NT Authenticated User in ASP.NET
Sometimes we want to log who is making changes to the system. I’m sure there are some SQL tricks you could do to pick it up when the stored procedure is called, but I’m a programmer instead of a database guy so I opt for the ASP.NET solution. ASP.NET has the HttpContext class which can get at all sorts of interesting underlying processes like items in cache, whether debugging is enabled or even just pulling back the timestamp off the server. For our purposes, we are going to step down into the Current.User.Identity.Name to find out who our user is. Now for this to work we need to have our program setup on IIS as its own application with Security enabled (Windows Basic). This will force the user to login using their NT network credentials. The login will actually look something like DomainName\UserName. More than likely we won’t be interested in what network they were signing in over just who they are. Current.User.Identity.Name gives us that and nothing else. Pretty handy when you’re trying to pin a system screw up on a user.
Read from a File with CSharp (c#)
I did the bookend post to this a couple weeks back (i.e. how to read from a file) so its time I wrapped this topic up. Where the writing function was StreamWriter, we instead use StreamReader to extract the text from the document. Pretty logical right? In the example below, I’m pulling a block of code out of a text file named code.txt so I can append it to the header of a document I’m getting ready to generate. So once I’ve told the StringReader which file we are working with, we need to loop through that file line by line to suck them into the reader. In this case I’m storing that output in a string variable I’ve called sCode. Finally, once we’ve captured all the file’s contents we close the StreamReader to release our resources. Don’t forget to make your reference to System.IO or Visual Studio is going to yell at you. Now I can take that sCode value and do with it what I will. Just like the StreamWriter class, we can accomplish a big task in a few lines of code, leaving more time to goof off looking for iPhone apps.
