| Subcribe via RSS

Err Msg: ‘Could Not Load Type _Default’ & ‘Server Application Unavailable’

February 5th, 2010 | Comments Off | Posted in ASP.NET
I thought I’d lump these two together since they seem to be interrelated. So I’m doing development on a dev box I haven’t worked with in a while. I have a Visual Studio project that works like a champ on my box, but as soon as I load it up to the dev I get the error message ‘Could Not Load Type _Default.’ I was thinking it was a web.config issue so I tried to massage that for a while with no luck. I’d set up the application correctly in IIS so it shouldn’t have any issues accessing the dll in the local bin folder. What I hadn’t counted on was the two versions of the .NET Framework running on this box. This was a 2.0 app I’d developed and my current application was defaulting over to 1.1. Updated this under the application in IIS, and up it came. It didn’t stay up for long though as I surfed through my application and quickly hit a ‘Server Application Unavailable’ error. I threw this project into the 2.0 application pool and everything settled down.

Find All Cookie Values in a Given Application via ASP.Net and c#

January 14th, 2010 | Comments Off | Posted in ASP.NET, C#

Cookies can be especially maddening at times if you don’t know what values are being stored within them. The following simple script is written in csharp and ASP.Net and allows you to see all of the cookies currently hanging around under a given application. Pretty handy when trying to fish yourself out of a problem.

Get NT Authenticated User in ASP.NET

August 12th, 2009 | Comments Off | Posted in ASP.NET, IIS

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.

Tags: , ,

Passing Parameters into XSLT Document with ASP.NET

July 28th, 2009 | Comments Off | Posted in ASP.NET, XSL

XSL documents do a great job styling XML content and doing it quickly, but its not always easy to define parameters within. Say you have a variable within your ASP.NET page that you need to send over to your XSL stylesheet, what do we do? XslTransform and XsltArgumentList are the key. In the code below, we define a new XslTransform then go about setting our XsltArgumentList. The XsltArgumentList takes an array of parameters so feel free to load it up. Once we have all of our parameters defined, we move to loading up our XSLT document via the Load method within XslTransform. The Server.MapPath just traces our path down the directory structure to the document in question. Finally, we need to associate all our content with the asp:Xml control on the page. We load the XML up. In this case, I had it in a string object. The we transform the content with the Xsl document we defined. Next, we associate our parameters we defined.

Now let’s take a look at the XSLT document. We have to define the xsl:param node so we have a placeholder to move our value into. These parameters definitions rest in the header of the document between the xsl:stylesheet and the xsl:template tags. As you can see, we’ve named our variable ‘myVariable’ and given it a default value of ’123′ in case we don’t have a value in which to send over. This default value will be overwritten when we make our call from the ASPX page. Then all we have to do is call our variable using the xsl:value-of select. Be sure to prepend the variable name with the dollar sign so it can properly access the value.

Delete Parent XML Node from Querying Child Attribute Using XPath & ASP.NET

July 9th, 2009 | Comments Off | Posted in ASP.NET, XML

So I’m receiving this XML string from an affiliate provider and evidently they don’t do any scrubbing on this data before kicking it my way. There are numerous instances of garbage node (i.e. test transaction – don’t put online). So I was tasked with cleaning up what they did not. I was looking to dig into the XML document and identify which child node innertext had the offensive text by querying the attribute hinged to that particular node. Take a look below at the XML structure I’m dealing with.

So in the following, say we wanted to delete all the Sleep Inn’s. We got a lumpy bed last time and the receptionist was smoking weed at the counter. Out you go Sleep Inn. The following code block accomplishes this.

So we’re using XPath to dig down to that description node. Once we are there, we create an XmlNodeList of all the nodes that fit this condition set in the XPath statement. Then we find which of these description nodes have “Sleep Inn” within their InnerText so we can define a the parentNode and remove all those child nodes. In all it scalps everything down to the <hot> tag. If we also wanted to get rid of this empty stub, we’d do a Regex statement to replace the start and end tag with blank space. Not the most elegant solution, but it works.

Working with XSLTransform and ASP:XML Controls in ASP.NET

July 7th, 2009 | Comments Off | Posted in ASP.NET, XML, XSL

Its a bit criminal how long its been since I worked with XSLT. I had this hellish project early in my programming career building a XML/XSLT program in ASP (yeah it was a while ago). I think it scarred me so bad I never had a desire to touch the stuff again. Really since you are able to read XML data straight into GridViews, there isn’t a whole lot of instances in my day to day coding life where I can’t just get by with that. Well today I had an issue where I was getting an XML datafeed from an affiliate provider and trying to find the best way to consume it. The big gotcha that kept me from going the easy GridView route was the format the data was in. It is ugly. The defining values are housed in the attributes and the node names are all the same (see below). What numbnuts designed this thing?

Anyway after trying to traverse the nodes, regenerate the XML document and other generally painful things to get the data to cooperate, I had a eureka moment to just plug it into an XSLT stylesheet. Talk about making my life incredibly easy. Here is the grand total of what it took to get the two elements plugged into my ASPX page. Notice the top 4 lines are my call to the affiliate site to get the XML dataset and line 5 is plugging the XML into the asp:XML control. Basically, one line of code. I like it.

Next, its time to dig into the XSLT. I've stripped this down to the essentials so we can focus on what is going on. Our xsl:for-each statement on line 15 drops down into the /response/result/hot node then our xsl:when tests to insure we bypass any test records the affiliate provider may have included. Next, we loop through the str node and pull out all of our relevant attributes (i.e. str[@name='description']). On line 41, we throw in our catchall for those datasets that come back without records.

All in all its pretty straight forward. I had lots of bells and whistles I had to incorporate to make this makeshift GridView work like it traditionally would under ASP.NET. Over the next few days, I'll post these extras.

Tags: , , , ,

Integrating Tooltip Functionality into a Datagrid in ASP.NET 1.0

June 17th, 2009 | Comments Off | Posted in ASP.NET

I know what you are thinking, “why doesn’t he just build this in 2.0 and make it a gridview? It all comes built-in.” Well sometimes we have a small update to make to an old system, and it doesn’t make sense to do the heavy lifting of a system rewrite. Then again, I may just be lazy. So the easiest approach is going to be one based on javascript. A couple years back, I ran across this handy file (wz_tooltip.js) from Walter Zorn that makes this job a breeze. Simply include the downloaded file within the footer of your page:

Now we focus on the datagrid. On the item we are looking to wire up with the tooltip, we’re going to set the onMouseOver attribute within the anchor tag. Within the onMouseOver, we return the escape function with the phrase we are looking to display in the tooltip:

In the previous example, I’m putting the tooltip over an image file, and the text that is displayed is the ‘control’ field pulled from the database. That is it. You were expecting more code? Sorry to disappoint you.

Now I haven’t tested this with images or should you want to do any fancy formatting with your text. You may have to play around with the javascript code or keep searching for another solution if that is the hole you find yourself in.

Tags: , ,

Format DateTime & Currency in ASP.NET from Database Output

June 8th, 2009 | Comments Off | Posted in ASP.NET, Uncategorized

Pretty easy one today. The database is spitting back the datetime stamp as 6/9/2009 12:05:42 AM and you need to drop the time. No problem. We just need to convert the database output to datetime format then set the date format in the ToString function.

This gives us that nice clean format we were looking for. Here are a variety of other options when it comes to formats for the datetime.

If we wanted to format currency, we would place it in the following format:

Tags: , ,

Filter Gridview via DropDownList & Search TextBox in ASP.NET

May 14th, 2009 | Comments Off | Posted in ASP.NET

Have you ever developed one of those systems users just seem to love to use? I’ll admit its a good problem to have, yet they just pile on the records one-by-one until your small band-aid system starts to collapse under its own lack of usability. A few years back, I created a graphics manager program for the marketing crew to keep track of their myriad of buttons, banners and general digital assets. I let the graphics guys drop the image in the appropriate folder that corresponded to an image category then the management system sifted through those folders to show what was there. Simple right? Wrong. Three years later, it is a mess of mammoth proportions. You can’t find anything, and its almost not like having anything to manage these resources at all.

So I’ve decided to database all these resources by associating them with categories, keyword tags, image dimensions, and title/description. So the question becomes how to let the users sift through all these new fields without the interface getting bogged down in the clutter? The system’s default page is a gridview listing all the graphics that currently in the system. Along the top, I’ve place two dropdownlist controls and a TextBox control. The dropdownlists will allow me to filter the grid based on the category and/or dimensions of the control, and the textbox will allow me to do specific searches on a given term for even greater specification.

So lets take a look at the ASPX side of things. Below we have the GridView. I’ve cleaned up the code to focus on the essential elements. Nothing out of the ordinary here. Just your basic SqlDataSource feeding back the relevant fields to the GridView.

Now let’s checkout the Header elements that will serve as our content filters. Same as the Gridview, nothing special here just filling out our datasources.

So if our ASPX is so plain Jane, where is all the fun happening? The codebehind of course. All the SelectIndexChanged and Search_OnClick functions reference the same method — parseFilters. Essentially we are doing the same thing whenever a user makes a selection.

parseFilters just does a survey to see what is in each field to build the conditional filter. Whenever one of these boxes is set to something other than the default, we tack that value onto sCondition. Once we’ve stepped through each possibility, we set the FilterExpression of our GridView’s SqlDataSource equal to sCondition.

That’s all there is to it. One hangup to be aware of. If the GridView comes back blank, it means that no selections met your search. If you are sure there are variables that should be getting served up, take advantage of that Response.Write of sCondition I have included to see what exactly is getting passed back to the Datasource. It can save you lots of time wrapping yourself in frustration.

Now you have a nice, simple way to drill down on your data so your users can find exactly what they are looking for with minimal effort.

Tags: , ,

Add Default Value in DropDownList using ASP.NET 2.0

May 11th, 2009 | Comments Off | Posted in ASP.NET

So we have a DropDownList in ASP.NET. The cool thing is, the framework gurus have made life a lot easier on us programmers in 2.0 in that the asp:DropDownList control and its cooresponding SqlDataSource control are side-by-side in design mode allowing you to wire up your DropDownList without ever touching the codebehind. It does beg the question of how to fill the default value though. Say you have some sort of personnel application, you don’t always want to default the option to Angela just because she’s numero uno in the list. We need to slide in a placeholder prior to the first name that prompts the user for action like “-Select an Employee-”. This is very easy. In the Page_Load event we are going to put the following:

Take particular notice of that last line. The AppendDataBoundItems allows the new default item to be included when we tack on the DataSource. Also note that this block needs to be wrapped in between a if (!IsPostBack) conditional to ensure that we don’t erase our user’s selection when we go to process out the selections.

For those interested in how we would have done this in ASP.NET 1.0, its basically this line of code that would come directly after the DataBind statement.

Tags: , ,