Posts

ASP.NET: Change page title based on database to which you're connecting

On occasion, you may find it useful to provide a visual cue that the user is not in an application's production environment. This is especially useful during a late night crunch when the developers, system administrators, and the Q.A. team are distracted and tired. Below is some code which allows you to change the page title and its style based on the database specified in a connection string. Note that we are parsing an Entity Framework connection string, not an ADO.NET connection string. Site.Master <div class="navbar navbar-inverse navbar-fixed-top">     <div class="container">         <div class="navbar-header">             <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">                 <span class="icon-bar"></span>                 <span class="...

List of Refresher Tutorials on Advanced Transact-SQL Techniques

Image
It never hurts to go back and look at the fundamentals. For instance, I had forgotten about the APPLY operator and was rusty on the PIVOT operator. SQLServerCentral.com has a good list of tutorials, Stairway to Advanced T-SQL , that hits most of the advanced fundamentals. http://www.sqlservercentral.com/stairway/119892/ Enjoy!

Fixing the error: "The element 'entityFramework' has invalid child element 'providers'. List of possible elements expected: 'contexts'"

If you're getting the error message: The element 'entityFramework' has invalid child element 'providers'. List of possible elements expected: 'contexts'. and you're using Visual Studio 2012 or Visual Studio 2013, then you can download and install  Entity Framework 6 Tools for Visual Studio 2012 & 2013 . These tools update the schema used to validate the configuration files for your projects. Entity Framework 6 Tools for Visual Studio 2012 & 2013 https://www.microsoft.com/en-us/download/details.aspx?id=40762

Most Likely Cause of the C# Error: "Non-static method requires a target"

I've encountered this error twice in the last two days, both times occurring while with a LINQ query and Entity Framework. And, in both cases, the problem stemmed from using a null value within the LINQ. Ultimately, the problem was farther upstream and not with my LINQ query at all (though better use of a try-catch statement would've been smart). The problem was an object with a null value being passed into the method. Once I figured that out, it was fairly easy to step through the debugger and see where my object wasn't being set to a legitimate value. So, if you get the error "Non-static method requires a target,", then verify that every value you're using within your LINQ statement contains a value, not a null. See the following posts on the web for more information and resolution to this error. Non-static method requires a target http://stackoverflow.com/questions/13717355/non-static-method-requires-a-target EF Non-static method requires a targe...

ASP.NET Routing Not Working in IIS

After deploying a brand new website to IIS on Windows Server 2008 R2, I encountered numerous issues. First, the web pages had no no styling. I could "View Source" and see that the code was correct, and I could browse to the folder containing the style sheets (bootstrap, my new obsession) and bring up the style sheet itself, but the application couldn't find the style sheets at run time on its own. Next, none of the links worked. The page "StudentsList", which should bring up "StudentsList.aspx" returned a HTTP 404 status. After futzing around a bit, it dawned on me that both issues stemmed from routing problems. In no time, I found several suggestions -- including good ol' Rick Strahl's blog -- most of which pointed to the same fix. Add the runAllManagedModulesForAllRequests attribute to the <modules> tag of the <system.WebServer> section of the web.config file. See Strahl's entry for more details: https://weblog.wes...

ASP.NET: Converting Web Forms to Content Pages

This is for my own reference while we convert some old sites to shiny new stuff. But, other people might find this useful. Every web page in the site was created as an ASP.NET Web Form. No Master Pages were used. To ensure a consistent look-and-feel and consolidate common pieces of code (such as the code that checks whether or not a user is logged in), the Web Forms should be converted to Content Pages. Follow the steps below to convert an existing Web Form to a new Content Page. Open the Web Form to the markup view. Add the following to the @Page directive at the top of the form: MasterPageFile="~/Site.Master" The resulting @Page directive should look something like this: <%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="Logon.aspx.vb" Inherits="SGBP.Logon" %>   Remove...

How to Add New Routes to ASP.NET Friendly URLs

If you haven't discovered or used Friendly URLs in your ASP.NET Web Forms applications, then you should take a look. If you're familiar with routing in ASP.NET MVS, then Friendly URLs in Web Forms will look much (if not exactly) the same. There's a handful of great overviews, how-to's, and tutorials out there. The following two were enough to jump start me: Introducing ASP.NET FriendlyUrls -- cleaner URLS, easier Routing, and Mobile Views for ASP.NET Web Forms , by Scott Hanselman Walkthrough: Using ASP.NET Routing in a Web Forms Application , from the MSDN Library You  an retrofit an older Web Forms applications to use Friendly URLs. Or, if you're creating a Web Forms application