Site: http://www.west-wind.com/weblog/ Link: http://feeds.feedburner.com/rickstrahl
by Rick Strahl via Rick Strahl's Web Log on 1/4/2012 2:44:15 AM
Ran into an annoying problem today with IE 9. Slowly updating some older sites with CSS 3 tags and for the most part IE9 does a reasonably decent job of working with the new CSS 3 features. Not all by a long shot but at least some of the more useful ones like border-radius and box-shadow are supported. Until today I was happy to see that IE supported box-shadow just fine, but I ran into a problem with some old markup that uses tables for its main layout sections. I found that inside of a table c ...
[ read more ]
by Rick Strahl via Rick Strahl's Web Log on 1/2/2012 10:36:44 AM
Ran into an interesting problem today on my CodePaste.net site: The main RSS and ATOM feeds on the site were broken because one code snippet on the site contained a lower ASCII character (CHR(3)). I don't think this was done on purpose but it was enough to make the feeds fail. After quite a bit of debugging and throwing in a custom error handler into my actual feed generation code that just spit out the raw error instead of running it through the ASP.NET MVC and my own error pipeline I found th ...
by Rick Strahl via Rick Strahl's Web Log on 12/23/2011 12:19:34 PM
If you're using Visual Studio 2010 to create Web applications, you probably have found out that the default Web templates for ASP.NET Web Forms and Master pages and plain HTML pages all create HTML 4 XHTML headers like this:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="$fileinputname$.aspx.cs" Inherits="$rootnamespace$.$classname$" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="h ...
by Rick Strahl via Rick Strahl's Web Log on 12/15/2011 10:19:04 AM
Recently I've seen quite a few questions pop up in regards to debugging ASP.NET application initialization. Most commonly I see something along these lines: I'm trying to debug my ASP.NET application and am starting the Debugger, but it won't stop on code in my Application_Start event Yup, been there done that. What does Application_Start do? Application_Start is pseudo handler that ASP.NET checks for during initialization of an ASP.NET application - if one exists it's fired during the applic ...
by Rick Strahl via Rick Strahl's Web Log on 12/11/2011 4:24:48 AM
Did you know that you can use HTML5 input types with ASP.NET WebForms controls? I wasn't sure until I tried it today:<asp:TextBox runat="server" ID="Username" Width="250px" type="email" /> which properly produces this HTML5 compliant HTML output:<input type="email" style="width:250px;" id="Username" name="Username"> That this works shouldn't come as a big surprise since ASP.NET always has supported 'extra' attributes on Web Controls to render into the HTML. However, the input type ...
by Rick Strahl via Rick Strahl's Web Log on 12/6/2011 1:04:04 PM
I've been thrown back to using plain old ADO.NET for a bit in a legacy project I'm helping one of my customers with and in the process am finding a few new ways to take advantage of .NET 4 language features to make a number of operations easier. Specifically I'm finding that the new Dynamic type in .NET 4.0 can make a number of operations easier to use and considerably cleaner to read and type. A couple of weeks ago I posted an example of a DynamicDataRow class that uses dynamic to expose DataRo ...
by Rick Strahl via Rick Strahl's Web Log on 11/30/2011 10:23:33 AM
So, how do you display time values in your Web applications? Displaying date AND time values in applications is lot less standardized than date display only. While date input has become fairly universal with various date picker controls available, time entry continues to be a bit of a non-standardized. In my own applications I tend to use the jQuery UI DatePicker control for date entries and it works well for that. Here's an example: The date entry portion is well defined and it makes perfect ...
by Rick Strahl via Rick Strahl's Web Log on 11/24/2011 11:13:23 AM
I've been thrown back into an older project that uses DataSets and DataRows as their entity storage model. I have several applications internally that I still maintain that run just fine (and I sometimes wonder if this wasn't easier than all this ORM crap we deal with with 'newer' improved technology today - but I disgress) but use this older code. For the most part DataSets/DataTables/DataRows are abstracted away in a pseudo entity model, but in some situations like queries DataTables and DataR ...
by Rick Strahl via Rick Strahl's Web Log on 11/11/2011 12:39:15 PM
I learned something new today. Not uncommon, but it's a core .NET runtime feature I simply did not know although I know I've run into this issue a few times and worked around it in other ways. Today there was no working around it and a few folks on Twitter pointed me in the right direction. The question I ran into is: How do I create a type instance of a generic type when I have dynamically acquired the type at runtime? Yup it's not something that you do everyday, but when you're writing co ...
by Rick Strahl via Rick Strahl's Web Log on 11/3/2011 11:55:36 AM
I frequently get questions about which option to use for creating AJAX and REST backends for ASP.NET applications. There are many solutions out there to do this actually, but when I have a choice - not surprisingly - I fall back to my own tools in the West Wind West Wind Web Toolkit. I've talked a bunch about the 'in-the-box' solutions in the past so for a change in this post I'll talk about the tools that I use in my own and customer applications to handle AJAX and REST based access to service ...
by Rick Strahl via Rick Strahl's Web Log on 10/10/2011 7:56:48 PM
One thing that frequently comes up in discussions when using jQuery is how to best load the jQuery library (as well as other commonly used and updated libraries) in a Web application. Specifically the issue is the one of versioning and making sure that you can easily update and switch versions of script files with application wide settings in one place and having your script usage reflect those settings in the entire application on all pages that use the script. Although I use jQuery as an examp ...
by Rick Strahl via Rick Strahl's Web Log on 10/9/2011 10:58:39 AM
Here's something I didn't find out until today: You can use Visual Studio to easily create registrationless COM manifest files for you with just a couple of small steps. Registrationless COM lets you use COM component without them being registered in the registry. This means it's possible to deploy COM components along with another application using plain xcopy semantics. To be sure it's rarely quite that easy - you need to watch out for dependencies - but if you know you have COM components tha ...
by Rick Strahl via Rick Strahl's Web Log on 10/5/2011 10:29:10 AM
WebResources in ASP.NET are pretty useful feature. WebResources are resources that are embedded into a .NET assembly and can be loaded from the assembly via a special resource URL. WebForms includes a method on the ClientScriptManager (Page.ClientScript) and the ScriptManager object to retrieve URLs to these resources. For example you can do: ClientScript.GetWebResourceUrl(typeof(ControlResources), ControlResources.JQUERY_SCRIPT_RESOURCE); GetWebResourceUrl requires a type (which is used for ...
by Rick Strahl via Rick Strahl's Web Log on 9/27/2011 11:50:56 AM
I don't know about you but I frequently need property bags in my applications to store and possibly cache arbitrary data. Dictionary<T,V> works well for this although I always seem to be hunting for a more specific generic type that provides a string key based dictionary. There's string dictionary, but it only works with strings. There's Hashset<T> but it uses the actual values as keys. In most key value pair situations for me string is key value to work off. Dictionary<T,V> w ...
by Rick Strahl via Rick Strahl's Web Log on 9/24/2011 1:44:44 AM
I introduced CodePaste.NET more than 2 years ago. In case you haven't checked it out it's a code-sharing site where you can post some code, assign a title and syntax scheme to it and then share it with others via a short URL. The idea is super simple and it's not the first time this has been done, but it's focused on Microsoft languages and caters to that crowd. Show your own code from the Web There's another feature that I tweeted about recently that's been there for some time, but is not use ...
by Rick Strahl via Rick Strahl's Web Log on 9/19/2011 2:50:56 AM
Here's an odd requirement: I need to figure out what version of IIS is available on a given machine in order to take specific configuration actions when installing an IIS based application. I build several configuration tools for application configuration and installation and depending on which version of IIS is available on IIS different configuration paths are taken. For example, when dealing with XP machine you can't set up an Application Pool for an application because XP (IIS 5.1) didn't su ...
by Rick Strahl via Rick Strahl's Web Log on 8/6/2011 10:44:16 PM
Some time back I created a data base driven ASP.NET Resource Provider along with some tools that make it easy to edit ASP.NET resources interactively in a Web application. One of the small helper features of the interactive resource admin tool is the ability to do simple translations using both Google Translate and Babelfish. Here's what this looks like in the resource administration form: When a resource is displayed, the user can click a Translate button and it will show the current resou ...
by Rick Strahl via Rick Strahl's Web Log on 7/20/2011 7:02:02 AM
Ran into a question from a client the other day that asked how to deal with Internet Connection settings for running HTTP requests. In this case this is an old FoxPro app and it's using WinInet to handle the actual HTTP connection. Another client asked a similar question about using the IE Web Browser control and configuring connection properties. Regardless of platform or tools used to do HTTP connections, you can probably configure custom connection and proxy settings in your applicatio ...
by Rick Strahl via Rick Strahl's Web Log on 7/1/2011 7:32:22 AM
Here's a trivial but quite useful function that I frequently need in dynamic execution of code: Finding the innermost exception when an exception occurs, because for many operations (for example Reflection invocations or Web Service calls) the top level errors returned can be rather generic. A good example - common with errors in Reflection making a method invocation - is this generic error: Exception has been thrown by the target of an invocation In the debugger it looks like this: In t ...
by Rick Strahl via Rick Strahl's Web Log on 6/9/2011 6:15:51 PM
I’ve been working on a sample application that needs to load some generated display content into the Web Browser control and I’ve been wanting to interact with this content. One of the things I want to do is use some transitions like modal overlays and activity displays while pages load – in other words do some Ajax based UI functionality but with data that is provided by the host application. The process for this goes something like this: Bring up the form Based on parameters provided ...
by Rick Strahl via Rick Strahl's Web Log on 5/28/2011 8:21:47 PM
Today I got a call from a customer and we were looking over an older application that uses a lot of tables to display financial and other assorted data. The application is mostly meta-data driven with lots of layout formatting automatically driven through meta data rather than through explicit hand coded HTML layouts. One of the problems in this apps are tables that display a non-fixed amount of data. The users of this app don't want to use paging to see more data, but instead want to display ov ...
by Rick Strahl via Rick Strahl's Web Log on 5/2/2011 10:17:48 AM
GZip encoding in ASP.NET is pretty easy to accomplish using the built-in GZipStream and DeflateStream classes and applying them to the Response.Filter property. While applying GZip and Deflate behavior is pretty easy there are a few caveats that you have watch out for as I found out today for myself with an application that was throwing up some garbage data. But before looking at caveats let’s review GZip implementation for ASP.NET. ASP.NET GZip/Deflate Basics Response filters basically ...
by Rick Strahl via Rick Strahl's Web Log on 4/21/2011 5:15:35 AM
Ran into a nasty issue last week when all of a sudden many of my old applications that are using WinInet for HTTP access started failing. Specifically, the WinInet HttpSendRequest() call started failing with an error of 2, which when retrieving the error boils down to: WinInet Error 2: The system cannot find the file specified Now this error can pop up in many legitimate scenarios with WinInet such as when no Internet connection is available or the HTTP configuration (usually configured in Int ...
by Rick Strahl via Rick Strahl's Web Log on 4/11/2011 9:16:22 AM
Well, it looks like we’ve finally arrived at a place where at least all of the latest versions of main stream browsers support rounded corners and box shadows. The two CSS properties that make this possible are box-shadow and box-radius. Both of these CSS Properties now supported in all the major browsers as shown in this chart from QuirksMode: In it’s simplest form you can use box-shadow and border radius like this: .boxshadow { -moz-box-shadow: 3px 3px 5px #535353; -webkit-box-shadow ...
by Rick Strahl via Rick Strahl's Web Log on 4/4/2011 8:07:37 PM
I’ve been having a few problems with my Windows 7 install and trying to get IIS applications to run properly in 64 bit. After installing IIS and creating virtual directories for several of my applications and firing them up I was left with the following error message from IIS: Calling LoadLibraryEx on ISAPI filter “c:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_filter.dll” failed This is on Windows 7 64 bit and running on an ASP.NET 4.0 Application configured for running 64 bit (32 bit ...
by Rick Strahl via Rick Strahl's Web Log on 4/1/2011 8:50:52 AM
Do you work with AJAX requests a lot and need to quickly check URLs for JSON results? Then you probably know that it’s a fairly big hassle to examine JSON results directly in the browser. Yes, you can use FireBug or Fiddler which work pretty well for actual AJAX requests, but if you just fire off a URL for quick testing in the browser you usually get hit by the Save As dialog and the download manager, followed by having to open the saved document in a text editor in FireFox. Enter JSONView whic ...
by Rick Strahl via Rick Strahl's Web Log on 3/28/2011 10:02:47 PM
As of version 4.0 ASP.NET natively supports routing via the now built-in System.Web.Routing namespace. Routing features are automatically integrated into the HtttpRuntime via a few custom interfaces. New Web Forms Routing Support In ASP.NET 4.0 there are a host of improvements including routing support baked into Web Forms via a RouteData property available on the Page class and RouteCollection.MapPageRoute() route handler that makes it easy to route to Web forms. To map ASP.NET Page routes is ...
by Rick Strahl via Rick Strahl's Web Log on 3/27/2011 8:14:58 PM
I ran into a nasty little problem today when deploying an application using ASP.NET 4.0 Routing to my live server. The application and its Routing were working just fine on my dev machine (Windows 7 and IIS 7.5), but when I deployed (Windows 2008 R1 and IIS 7.0) Routing would just not work. Every time I hit a routed url IIS would just throw up a 404 error: This is an IIS error, not an ASP.NET error so this doesn’t actually come from ASP.NET’s routing engine but from IIS’s handling of express ...
by Rick Strahl via Rick Strahl's Web Log on 3/22/2011 11:24:53 PM
.NET 4.0 introduces some nice changes that makes it easier to run .NET EXE type applications directly off network drives. Specifically the default behavior – that has caused immense amount of pain – in previous versions that refused to load assemblies from remote network shares unless CAS policy was adjusted, has been dropped and .NET EXE’s now behave more like standard Win32 applications that can load resources easily from local network drives and more easily from other trusted remote locations ...
by Rick Strahl via Rick Strahl's Web Log on 2/22/2011 9:17:44 AM
Here's a scenario I've run into on a few occasions: I need to be able to monitor certain CSS properties on an HTML element and know when that CSS element changes. The need for this arose out of wanting to build generic components that could 'attach' themselves to other objects and monitor changes on the ‘parent’ object so the dependent object can adjust itself accordingly. What I wanted to create is a jQuery plug-in that allows me to specify a list of CSS properties to monitor and have a funct ...
by Rick Strahl via Rick Strahl's Web Log on 2/11/2011 1:14:45 PM
Man I can't believe this. I'm still mucking around with OFX servers and it drives me absolutely crazy how some these servers are just so unbelievably misconfigured. I've recently hit three different 3 major brokerages which fail HTTP validation with bad or corrupt certificates at least according to the .NET WebRequest class. What's somewhat odd here though is that WinInet seems to find no issue with these servers - it's only .NET's Http client that's ultra finicky. So the question then becomes h ...
by Rick Strahl via Rick Strahl's Web Log on 1/30/2011 11:44:57 AM
This is a question that comes up quite frequently: I have a form with several submit or link buttons and one or more of the buttons needs to open a new Window. How do I get several buttons to all post to the right window? If you're building ASP.NET forms you probably know that by default the Web Forms engine sends button clicks back to the server as a POST operation. A server form has a <form> tag which expands to this: <form method="post" action="default.aspx" id="form1"> Now you ...
by Rick Strahl via Rick Strahl's Web Log on 1/17/2011 11:04:59 AM
Did it again today: For logging purposes I needed to capture the full Request.Form data as a string and while it’s pretty easy to retrieve the buffer it always takes me a few minutes to remember how to do it. So I finally wrote a small helper function to accomplish this since this comes up rather frequently especially in debugging scenarios or in the immediate window. Here’s the quick function to get the form buffer as string: /// <summary> /// Returns the content of the POST buffer as s ...
by Rick Strahl via Rick Strahl's Web Log on 1/14/2011 8:45:39 PM
I’m working on an older FoxPro application that’s using .NET Interop and this app loads its own copy of the .NET runtime through some of our own tools (wwDotNetBridge). This all works fine and it’s fairly straightforward to load and host the runtime and then make calls against it. I’m writing this up for myself mostly because I’ve been bitten by these issues repeatedly and spend 15 minutes each However, things get tricky when calling specific versions of the .NET runtime since .NET 4.0 has shi ...
by Rick Strahl via Rick Strahl's Web Log on 1/12/2011 11:06:36 PM
When I posted my Razor Hosting article a couple of weeks ago I got a number of questions on how to get IntelliSense to work inside of Visual Studio while editing your templates. The answer to this question is mainly dependent on how Visual Studio recognizes assemblies, so a little background is required. If you open a template just on its own as a standalone file by clicking on it say in Explorer, Visual Studio will open up with the template in the editor, but you won’t get any IntelliSense on ...
by Rick Strahl via Rick Strahl's Web Log on 1/10/2011 9:02:16 PM
If you’re building WCF REST Services you may find that WCF’s OperationContext, which provides some amount of access to Http headers on inbound and outbound messages, is pretty limited in that it doesn’t provide access to everything and sometimes in a not so convenient manner. For example accessing query string parameters explicitly is pretty painful: [OperationContract] [WebGet] public string HelloWorld() { var properties = OperationContext.Current.IncomingMessageProperties; var propert ...
by Rick Strahl via Rick Strahl's Web Log on 1/6/2011 10:54:52 PM
I’m struggling with an interesting problem with WCF REST since last night and I haven’t been able to track this down. I have a WCF REST Service set up and when accessing the .SVC file it crashes with a version mismatch for System.ServiceModel: Server Error in '/AspNetClient' Application. Could not load type 'System.ServiceModel.Activation.HttpHandler' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.Description: An unhandled exception occu ...
by Rick Strahl via Rick Strahl's Web Log on 12/28/2010 4:16:09 AM
Microsoft’s new Razor HTML Rendering Engine that is currently shipping with ASP.NET MVC previews can be used outside of ASP.NET. Razor is an alternative view engine that can be used instead of the ASP.NET Page engine that currently works with ASP.NET WebForms and MVC. It provides a simpler and more readable markup syntax and is much more light weight in terms of functionality than the full blown WebForms Page engine, focusing only on features that are more along the lines of a pure view engine ( ...
by Rick Strahl via Rick Strahl's Web Log on 12/21/2010 2:17:34 AM
Here’s a nice and simple path utility that I’ve needed in a number of applications: I need to find a relative path based on a base path. So if I’m working in a folder called c:\temp\templates\ and I want to find a relative path for c:\temp\templates\subdir\test.txt I want to receive back subdir\test.txt. Or if I pass c:\ I want to get back ..\..\ – in other words always return a non-hardcoded path based on some other known directory. I’ve had a routine in my library that does this via some leng ...
by Rick Strahl via Rick Strahl's Web Log on 11/19/2010 1:12:33 AM
I’m working on some legacy code for a customer today and dealing with a page that has my favorite ‘friend’ on it: A GridView control. The ASP.NET GridView control (and also the older DataGrid control) creates some pretty messed up HTML. One of the more annoying things it does is to generate all rows including the header into the page in the <tbody> section of the document rather than in a properly separated <thead> section. Here’s is typical GridView generated HTML output: <tab ...
by Rick Strahl via Rick Strahl's Web Log on 9/13/2010 11:25:52 PM
I’ve written quite a bit about Visual FoxPro interoperating with .NET in the past both for ASP.NET interacting with Visual FoxPro COM objects as well as Visual FoxPro calling into .NET code via COM Interop. COM Interop with Visual FoxPro has a number of problems but one of them at least got a lot easier with the introduction of dynamic type support in .NET. One of the biggest problems with COM interop has been that it’s been really difficult to pass dynamic objects from FoxPro to .NET and get th ...
by Rick Strahl via Rick Strahl's Web Log on 9/8/2010 5:40:34 AM
The other day I got a question about how to call an ASP.NET ASMX Web Service or PageMethods with the POST data from a Web Form (or any HTML form for that matter). The idea is that you should be able to call an endpoint URL, send it regular urlencoded POST data and then use Request.Form[] to retrieve the posted data as needed. My first reaction was that you can’t do it, because ASP.NET ASMX AJAX services (as well as Page Methods and WCF REST AJAX Services) require that the content POSTed to the s ...
by Rick Strahl via Rick Strahl's Web Log on 8/19/2010 8:40:34 PM
There’s been a change in the way the ValidateRequest attribute on WebForms works in ASP.NET 4.0. I noticed this today while updating a post on my WebLog all of which contain raw HTML and so all pretty much trigger request validation. I recently upgraded this app from ASP.NET 2.0 to 4.0 and it’s now failing to update posts. At first this was difficult to track down because of custom error handling in my app – the custom error handler traps the exception and logs it with only basic error informati ...
by Rick Strahl via Rick Strahl's Web Log on 6/7/2010 7:58:51 PM
I’ve run into a serious snag trying to debug a .NET 2.0 assembly that is called from unmanaged code in Visual Studio 2010. I maintain a host of components that using COM interop and custom .NET runtime hosting and ever since installing Visual Studio 2010 I’ve been utterly blocked by VS 2010’s inability to apparently debug .NET 2.0 assemblies when launching through unmanaged code. Here’s what I’m actually doing (simplified scenario to demonstrate): I have a .NET 2.0 assembly that is compile ...
by Rick Strahl via Rick Strahl's Web Log on 5/22/2010 11:22:59 AM
The dynamic type in C# 4.0 is a welcome addition to the language. One thing I’ve been doing a lot with it is to remove explicit Reflection code that’s often necessary when you ‘dynamically’ need to walk and object hierarchy. In the past I’ve had a number of ReflectionUtils that used string based expressions to walk an object hierarchy. With the introduction of dynamic much of the ReflectionUtils code can be removed for cleaner code that runs considerably faster to boot. The old Way - Reflection ...
by Rick Strahl via Rick Strahl's Web Log on 5/4/2010 7:16:00 AM
In the last installment I talked about the core changes in the ASP.NET runtime that I’ve been taking advantage of. In this column, I’ll cover the changes to the Web Forms engine and some of the cool improvements in Visual Studio that make Web and general development easier. WebForms The WebForms engine is the area that has received most significant changes in ASP.NET 4.0. Probably the most widely anticipated features are related to managing page client ids and of ViewState on WebF ...
by Rick Strahl via Rick Strahl's Web Log on 1/21/2010 12:32:30 AM
A few days ago my buddy Ben Jones pointed out that he ran into a bug in the ScriptContainer control in the West Wind Web and Ajax Toolkit. The problem was basically that when a Server.Transfer call was applied the script container (and also various ClientScriptProxy script embedding routines) would potentially fail to load up the specified scripts. It turns out the problem is due to the fact that the various components in the toolkit use request specific singletons via a Current property. I use ...
by Rick Strahl via Rick Strahl's Web Log on 12/24/2009 10:05:11 AM
Ran into an odd behavior today with a many to many mapping of one of my tables in LINQ to SQL. Many to many mappings aren’t transparent in LINQ to SQL and it maps the link table the same way the SQL schema has it when creating one. In other words LINQ to SQL isn’t smart about many to many mappings and just treats it like the 3 underlying tables that make up the many to many relationship. Iain Galloway has a nice blog entry about Many to Many relationships in LINQ to SQL. I can live with that – ...
by Rick Strahl via Rick Strahl's Web Log on 12/18/2009 11:00:53 PM
Got a note a couple of days ago from a client using one of my generic routines that wraps SmtpClient. Apparently whenever a file has been attached to a message and emailed with SmtpClient the file remains locked after the message has been sent. Oddly this particular issue hasn’t cropped up before for me although these routines are in use in a number of applications I’ve built. The wrapper I use was built mainly to backfit an old pre-.NET 2.0 email client I built using Sockets to avoid the CDO n ...
by Rick Strahl via Rick Strahl's Web Log on 12/14/2009 8:15:14 AM
Paging in ASP.NET has been relatively easy with stock controls supporting basic paging functionality. However, recently I built an MVC application and one of the things I ran into was that I HAD TO build manual paging support into a few of my pages. Dealing with list controls and rendering markup is easy enough, but doing paging is a little more involved. I ended up with a small but flexible component that can be dropped anywhere. As it turns out the task of creating a semi-generic Pager control ...
by Rick Strahl via Rick Strahl's Web Log on 11/13/2009 5:47:39 PM
During one of my Handlers and Modules session at DevConnections this week one of the attendees asked a question that I didn’t have an immediate answer for. Basically he wanted to capture response output completely and then apply some filtering to the output – effectively injecting some additional content into the page AFTER the page had completely rendered. Specifically the output should be captured from anywhere – not just a page and have this code injected into the page. Some time ago I poste ...
by Rick Strahl via Rick Strahl's Web Log on 10/12/2009 9:56:53 AM
LINQ to SQL by default loads related entities and entity sets by using Lazy Loading. Which means if you retrieve a list of entities in a query that references other entities these other entities are not actually loaded unless you physically access them. Lazy loading is quite useful in some scenarios – typically when you load up individual instances for display purposes in simple record based UIs, but it can be a real problem when displaying list based data that needs to have access to related da ...
by Rick Strahl via Rick Strahl's Web Log on 10/5/2009 8:38:32 AM
Func<T> has been in .NET for a while, but with the arrival of LINQ it’s moved into the limelight as main performer that makes Lambda expressions work. Func<T> is basically a generic delegate that makes it extremely easy to create all sorts of custom delegate signatures without having to explicitly implement the delegates separately. Events How often have you lamented the fact that you have to create a custom delegate for an event that needs to fire a method that uses non-typical ev ...
by Rick Strahl via Rick Strahl's Web Log on 9/24/2009 7:48:07 AM
So imagine you are running your ASP.NET application’s in medium trust and you want to access a debugger visualizer like this: by clicking on the little search icon in the debugger tooltip, you run into a message like this: The application you are debugging has insufficient privileges to allow the use of custom visualizers or more visually here failing with a DataTable visualizer: Ah yes, see the documentation. I know I should have read that one page pamphlet Microsoft ships for ...
by Rick Strahl via Rick Strahl's Web Log on 9/18/2009 4:15:24 AM
The #1 request I got on the CodePaste.net site - which provides a quick and easy way to publish and share code snippets publicly - has been to implement OpenId for authentication rather than the custom username/password login that’s been in use up until now. OpenId is a centralized login/authentication mechanism which handles authentication through one or more centralized OpenId providers. These providers live on the Web and are accessed through a forwarding and callback mechanism – you log in a ...
by Rick Strahl via Rick Strahl's Web Log on 9/16/2009 3:31:07 AM
I’ve discussed creating a WCF or ASMX Service proxy for operation with jQuery and without using the Microsoft AJAX libraries. This was some time ago and some things have changed since then – most notably the introduction native JSON parsers in IE 8 and FireFox 3.5 as well as some changes in .NET 3.5 SP1 that makes some JSON transfer tasks a little bit easier in some situations. So I think it’s time to revisit this topic and update the code I showed in the past. How the WCF ServiceProxy works T ...
by Rick Strahl via Rick Strahl's Web Log on 9/10/2009 11:33:58 PM
[9/12/2009 – Note this post is an update of an older post that discussed a wrapper around Marc Garbanski’s jQuery-calender control. This post updates to the current jQuery.ui version (1.72). The control has been integrated into the West Wind Web & Ajax Toolkit for ASP.NET and you can grab the code from there in the Westwind.Web project. The links to the sample and download point at the Toolkit] I've posted a wrapper ASP.NET around the jQuery.UI Datepickercontrol. This small client side cale ...
[9/12/2009 – Note this control has been updated to the latest version of jQuery UI DatePicker so the code in the post below is slightly out of date. The control has been integrated into the West Wind Web & Ajax Toolkit for ASP.NET and you can grab the code from there in the Westwind.Web project. The links to the sample and download point at the Toolkit] I've posted a wrapper ASP.NET around the jQuery Calendar control from Marc Garbanski. This small client side calendar control is compact, l ...
by Rick Strahl via Rick Strahl's Web Log on 8/18/2009 6:20:15 PM
Although I use Generics extensively, every once in a while it still throws me for a loop when dealing with complex generic parameters and inheritance. I recently ran into a situation where I needed to created a class hierarchy and needed to inherit generic parameters. Generics are great and for this particular implementation the simple base->specific type inheritance makes it really easy to define the business object classes without each instance having to specify the generic template types. ...
by Rick Strahl via Rick Strahl's Web Log on 8/4/2009 3:04:51 PM
In many applications it’s necessary to copy data between objects. Especially these days where we often have entities and Data Transfer Objects (DTO) where data needs to be shuttled back and forth between two objects I find it handy to have a simple routine that performs at least rudimentary, shallow data copying for me without manually having to write data mapping code at least if the properties identically or nearly identically. A few days ago I had a lengthy discussion about this topic on Twit ...
by Rick Strahl via Rick Strahl's Web Log on 7/30/2009 10:21:43 AM
It’s no secret that ASP.NET MVC is missing a few features that are native to Web Forms the most notable of which (for me anyway) is lack of access to the ClientScript functionality outside of Views. The Page.ClientScript object provides a host of features for retrieving WebResources and embedding script links into a page. If you need to access ClientScript from within an ASP.NET View, then you can still access this object, but many of its methods that output content in particular places in the ...
by Rick Strahl via Rick Strahl's Web Log on 7/20/2009 12:21:25 AM
As I’m working though my first MVC application I’ve run into a few problems with creating URLs based on ‘special characters’. Here’s a specific example, where I need to create links from a list of tags. In the example above a list like C#,ASP.NET,MVC is turned into a list of links that looks like this: The tags are stored as a simple comma delimited string and are split and turned into links using the UrlHelper’s Action() method. The following is an extension method on my application specific ...
by Rick Strahl via Rick Strahl's Web Log on 7/17/2009 6:30:53 AM
So I ran into an annoying problem today with an entity that has a timestamp. When imported LINQ to SQL will create a Binary type for this the timestamp and as it turns out this type does not serialize via XML. This means ASMX Web services fail as well as plain old XmlSerializer style serialization. You’ll get: System.Data.Linq.Binary cannot be serialized because it does not have a parameterless constructor. Uh, how can you build a new type for a data component that doesn’t serialize natively? ...
by Rick Strahl via Rick Strahl's Web Log on 7/14/2009 7:48:07 AM
LINQ to SQL handles a lot of functionality out of the box for you, including the ability to perform updates under transaction contexts for you transparently. If you modify, add or delete instances of entities the changes are updated in the context of a transaction when SubmitChanges() is called. This covers a wide range of operations and this is as it should be for an ORM: Transactions should be handled mostly transparently. Every once in a while though you may need to perform some update tasks ...
by Rick Strahl via Rick Strahl's Web Log on 6/29/2009 5:28:55 AM
Got a question in response to a Localization article today that asked how to store requested culture settings. In the article I recommend that easiest and most reliable way to switch cultures is to assign the culture when the application runs and allow the user to change cultures somewhere in the UI. When the culture is changed it’s up to the application to decide how to handle the actual culture change. One of the easiest things to do is write the change to a configuration setting and then exit ...
by Rick Strahl via Rick Strahl's Web Log on 6/19/2009 4:03:29 AM
I got an interesting question via email today that asked the question: “How do ASP.NET Application_ Event Handlers get hooked so that they are automatically fired?” If you’ve worked with ASP.NET for any amount of time you probably know about the global.asax file and its backing global class that holds event handlers for several common HttpApplication Event Handlers: public class Global : System.Web.HttpApplication { protected void Application_Start(object sender, EventArgs e) { ...
by Rick Strahl via Rick Strahl's Web Log on 6/14/2009 6:55:20 PM
I was surprised to find today that while putting together some localization samples that by default WPF bindings do not respect the current culture. For example check out this localized form that has been localized to German and is running with both Culture and UICulture in the de-DE locale: If you look at the highlighted formatting text you’ll notice that the form is localized (ie.the UICulture is applied) and that the active culture which in this case displays the CultureInfo.Curren ...
by Rick Strahl via Rick Strahl's Web Log on 5/26/2009 6:20:56 AM
Creating a full featured editable component that handles a number of scenarios is quite complex. Some time ago I started in on this process with a wwEditable plug-in which I’ve used in a number of applications. It works, but it’s fairly large and even so has a few rough edges for full generic use. However, if you’re just after a quick and dirty mechanism for editing some text for the purpose of updating it there’s actually an easier way using the contentEditable attribute on DOM elements. The n ...
by Rick Strahl via Rick Strahl's Web Log on 5/21/2009 7:31:45 PM
This might be one of those “Duh” moment posts that seems real obvious now, but this particular issue – trying to get OutputCache to work in an HttpHandler and having it not work because of an errand Response.End() - has caused me grief on a few occasions. Some time ago I posted a JavaScript Resource handler that serves server side ASP.NET resources to client side JavaScript. Bertrand commented on that post that I should be using OutputCache instead of writing values to the ASP.NET Element Cache ...
by Rick Strahl via Rick Strahl's Web Log on 5/18/2009 10:12:50 AM
I’ve tried an interesting experiment today trying to see if I can get LINQ to SQL to run with a custom ADO.NET Data Provider I’ve created some time ago. Basically I implemented a provider that is a proxy to a remote Web ‘service’ that can marshal SQL commands via Web Requests on a remote server. I implemented a custom provider for this interface that ships XML across the wire and marshals raw SQL commands to the Web server to process. It works well using plain ADO.NET and my own internal b ...
by Rick Strahl via Rick Strahl's Web Log on 4/29/2009 8:59:10 PM
Recently I’ve run into a problem on my production server where results that produce errors that are handled by the application (either in Application_Error or in some cases for JSON or XML based custom services) would return IIS error pages instead of my custom error content generated in code. Basically what’s happening in all of this handled error code is that the application somehow intercepts an error – either Application_Error, or in the case of a JSON service an exception in the RPC call fo ...
by Rick Strahl via Rick Strahl's Web Log on 4/24/2009 12:14:51 PM
I’ve run into a scenario a few times now where I ended up with a DataReader at the end of a service call that I want to serialize into JSON to feed to the client. Don’t start - I’m not recommending sticking a DataReader into your front end or JSON service! It’s not a common scenario and I certainly wouldn’t advocate that in a normal application scenario (DataReaders have no place in the front end), but in these cases I’ve been dealing with system components that spit out query results in D ...
by Rick Strahl via Rick Strahl's Web Log on 3/28/2009 11:33:54 PM
Every once in a while I run into the situation where I need an application root relative path in an ASP.NET application. Right now I need this for a few localization routines. In the ASP.NET Resource Provider model localization is based on resource sets which are referenced via – application relative paths (ie. subdir/page.aspx or page.aspx). Question is how do you get this relative path? For the current page this is actually quite easy. The HttpRequest object includes a handy AppRelativeCurr ...
by Rick Strahl via Rick Strahl's Web Log on 3/8/2009 12:06:59 PM
Nate Kohari has a great post regarding nice dynamic delegate implementation using LINQ expression trees. Go check it out, it’s a great example of the power of Expression Trees in an example that is actually understandable and also very useful. I’ll wait here… Basically what Nate’s code does is provide a dynamic method implementation for any generic method signature that you can provide via a MethodInfo structure. So what? Dynamic invocation isn’t difficult, right? After all Reflection provide ...
by Rick Strahl via Rick Strahl's Web Log on 2/20/2009 8:00:38 AM
Quite frequently in Web and Windows apps, I’ve found it necessary to display data values contained in an Enum type typically inside of a list or combobox type control. Assume that you want to display a drop down list from this enumeration of bug status types: public enum BugStatusTypes { Entered, InProcess, Fixed, ByDesign, NotReproducible, NoBug, None } You can then do something akin to this to turn that enumeration into values to use in the dropdown: protecte ...
by Rick Strahl via Rick Strahl's Web Log on 2/12/2009 12:01:55 PM
[updated 2/16/2009: Added support for imported schemas so WCF services can work] A couple of weeks back I have been working on a Web Service client tool for COM clients. With the SOAP Toolkit DOA one of the things that old (for me most FoxPro apps of clients) apps need to do is access Web Services and .NET is really become the only viable option if calling a complex service is required. I’ve been swamped with work in this area recently (which isn’t a bad thing) but clearly a lot of people are f ...
by Rick Strahl via Rick Strahl's Web Log on 2/5/2009 1:17:08 PM
I’ve been revisiting and refactoring some of my old utility libraries recently. One of my classes is WebUtils which is – duh - Web specific and really didn’t need to be in this general utility library and so I moved it off into my Web support library that contains the brunt of Web specific behavior like custom controls and general ASP.NET helpers. The Westwind.Web project naturally contains a reference to System.Web because it’s a Web project. After removing the Web functionality from the Westw ...
by Rick Strahl via Rick Strahl's Web Log on 1/19/2009 10:53:52 AM
Every time I need to load .NET assemblies from a non-default path in an application I end up spending quite a bit of time trying to get it right. Today was no different: I had a situation where I needed to create a type in a seperate AppDomain based on a dynamically generated assembly that might live in a directory other than the application’s base path. This is sort of like a perfect storm of combinations that are problematic for Assembly loading: Loading across AppDomains and loading an assemb ...
by Rick Strahl via Rick Strahl's Web Log on 12/19/2008 10:51:15 AM
Ah thought I go back to basics today for a post. An operation I rely on a lot when I’m working with text is the ability to extract strings with delimiters from within another string. RegEx can be quite useful for many scenarios of finding matches and extracting text, but personally for the 10 times a year when I need to use RegEx expressions I tend to relearn most of the cryptic syntax each time. What should take me a couple minutes usually turns into a half an hour of experimenting with RegEx B ...
by Rick Strahl via Rick Strahl's Web Log on 8/26/2008 1:18:44 PM
I'm calling a COM object from managed code that's returning a binary response, which is returned as a SafeArray of bytes from the COM server. My managed code uses Reflection to retrieve the result from the COM Server like this: // Results in a binary (SafeArray) response from COM object // .ToString shows: System.Byte[*] as the type object zipContent = wwUtils.CallMethodCom(this.HelpBuilder, "CreateHelpZip", "DOTNETASSEMBLY", "TestProject", ...
by Rick Strahl via Rick Strahl's Web Log on 4/27/2008 1:24:37 AM
Every once in a while when I write code that deals with Anonymous Delegates, I still kinda freak out when it comes to the behavior of closures and the variable scoping that goes along with it. For example, the following code uses a List<T>.Find() Predicate to search for items in the list and requires that a dynamic value is compared to: public void AddScript(ScriptItem script){ ScriptItem match = null; // *** Grab just the path if ...
by Rick Strahl via Rick Strahl's Web Log on 3/26/2008 8:57:18 AM
So I'm refactoring some code for an old side project, which is my old photoalbum app. I have built this thing back in the 1.x days and then updated it for 2.x and now it's going through another update for 3.5 just for fun. It's a nice side project that lets me play a bit with various AJAX features in jQuery. [Updated: 03/27/2008 - updated thanks to suggestions from commenters] Anyway I turned the project into a 3.5 project because it uses a number of collections that are manipulated in a variety ...
by Rick Strahl via Rick Strahl's Web Log on 1/24/2008 2:12:27 AM
C# 2.0 has a nice ?? operator that works as a shortcut for: string value1 = null;string value2 = "Test1";string result = value1 != null ? value1 : value2; which causes result containing Test1 or the second value. In C# you can shortcut this special null comparison case with the new ??: string result = value1 ?? value2; which is a little easier to write. This is probably not news to you, but what's really useful is that you can chain these operators together so you can do a w ...
by Rick Strahl via Rick Strahl's Web Log on 12/21/2007 7:52:34 AM
I'm fixing few issues in Html Help Builder related to HTML comments and how they are imported into Html Help Builder. While I'm working with this I'm checking things in VB and C# and I have to say that VB manages embedded <see> tags a heck of a lot nicer than C#. .In VB what happens as you type a comment like this: ''' <summary> ''' The <see cref="HelpBuilderTestLib.HelpBuilderTestClass" >Text we see in Help File</see> ''' </summary> ''' <v ...
by Rick Strahl via Rick Strahl's Web Log on 12/14/2007 2:33:49 PM
I've been racking my head over a 'generic' problem in relation to a WCF Web service client. I have an component that acts as a Web Service wrapper to proxy calls between a non-.NET client and a WCF Web Service client. The calls are working fine, but we have a rather large number of services that are being called and there's a bit of configuration code that needs to fire for initializing the Web Service client. The problem is the code is nearly identical for each of the service initializations e ...
by Rick Strahl via Rick Strahl's Web Log on 11/28/2007 9:04:15 AM
I keep running into issues in regards to auto-detection of file types when using StreamReader. StreamReader supports byte order mark detection and in most cases that seems to be working Ok, but if you deal with a variety of different file encodings for input files using the default detection comes up short. I posted a JavaScript Minifier application yesterday and somebody correctly pointed out that the text encoding was incorrect. It turns out part of the problem is the code I snatched from Dou ...
by Rick Strahl via Rick Strahl's Web Log on 11/16/2007 12:25:52 AM
One of the most convenient features of C# 3.0 is the ability to create new types 'on the fly' using Anonymous Types. Anonymous Types are essentially compiler generated types that you don't explicitly declare with an official type declaration. Rather you define the type inline as part of the code where you need to use the new type. Furthermore when the type is 'announced' you don't have to explicitly type each of the members that you create on the type due to the new inferred type discovery that' ...
by Rick Strahl via Rick Strahl's Web Log on 11/12/2007 9:20:27 AM
During my LINQ to SQL session at DevConnections somebody in the audience asked what happens behind the scenes when you use type initializers in C# 3.0 and well it turns out I gave a hedged answer with a guess that was - uhm - wrong. So here's a discussion of how this feature actually works. Type Initializers are a new language construct that allow for C# (and VB using similar syntax) to shortcut creating of custom constructors or writing additional code to initialize properties. For ex ...
by Rick Strahl via Rick Strahl's Web Log on 10/1/2007 7:04:23 AM
Ok, so I thought I had the detached entity state in LINQ to SQL figured out, only to have that thrown back into my face. Basically the word from Microsoft is that if you have an entity that was loaded through a LINQ to SQL DataContext at any point it cannot be re-attached to the DataContext. Note that all the stuff below works fine with 'connected' entities that are attached to a single instance of the DataContext. The following only applies to scenarios where the entity needs to get detached fr ...
by Rick Strahl via Rick Strahl's Web Log on 9/27/2007 11:59:51 AM
I've been talking about how I'm using a small business object wrapper around LINQ to SQL to provide better abstraction of the LINQ to SQL functionality and I suppose the time's come to be bit more specific. This is going to be a long post with a fair bit of code and a brief discussion of the whys and hows. So I want to share my ideas of what I'm thinking here and an overview of what I've built so far. It's not complete, but enough to work with to get a feel for it and I'm using it successfully w ...
by Rick Strahl via Rick Strahl's Web Log on 9/26/2007 7:43:23 AM
As I'm working through a sample application here with LINQ to SQL and a business layer that I've built I'm starting to find out some really cool things that you can do with LINQ to SQL that were not easily done before. So I use a business object abstraction layer that hosts the data context. Typically there's one business object per main entity but the idea is that the business objects are logicial abstractions rather than the physical abstractions that LINQ to SQL Entities are. S ...
by Rick Strahl via Rick Strahl's Web Log on 9/25/2007 6:34:47 AM
I found myself working with displaying time values a bit today for a demo app I'm building, and figured I share a few useful functions that I ended up creating. Basically, I have a time tracking sample and I need to display time values in a variety of ways as well as deal with dates that are rounded to a specific minute interval. This isn't exactly rocket science although I have to admit I stumbled a bit on the time value parsing routine. Here are the routines: public class TimeUtilities{&nbs ...
by Rick Strahl via Rick Strahl's Web Log on 9/21/2007 7:01:32 AM
I'm mucking around with a bit of code today that's using AJAX and returning some data from my business layer that's using LINQ to SQL Entities. I mentioned some time that one issue that I ran into and continue to bump my head against is that LINQ to SQL has big issues serializing its entities. The problem with serialization of any kind is that L2S creates cirular references with default models and these circular references are blowing up serialization. As I mentioned in my last post this causes ...
by Rick Strahl via Rick Strahl's Web Log on 9/17/2007 7:32:25 AM
I'm working on an old app that interfaces with a legacy COM object. In reviewing some of my wwDataBinder code I noticed that it didn't work against COM objects for databinding. With a few minor changes I've been able to make the binding code work by using the the higher level Type.InvokeMember method which works with COM objects for getting and setting properties and calling COM objects (although that method is quite a bit slower). However, for unbinding I need to figure out first what the type ...
by Rick Strahl via Rick Strahl's Web Log on 9/11/2007 7:45:18 PM
In my last column I talked about LINQ as the key feature in .NET 3.5. ASP.NET 3.5 is not going to see a whole bunch of improvement in terms of new features with just a few new controls and roll up of some of the slip stream features like Microsoft ASP.NET AJAX and IIS 7 support directly rolled into the .NET framework. The big news in ASP.NET 3.5 – and .NET 3.5 in general - is LINQ and its related new features. In the last column I introduced some key features of LINQ and why I think it’s easily ...
by Rick Strahl via Rick Strahl's Web Log on 9/3/2007 5:40:37 AM
One of the important that things that you will likely have to do at one point or another with entity objects is serialize them. This could be for Web Services most commonly but could be for any sort of storage or transport scenario. There are a number of pitfalls with this scenario however, primarily because LINQ to SQL will very likely generate circular references into your entity model from your data and XML Serialization will fail outright in that scenario. For example, say you have a custom ...
by Rick Strahl via Rick Strahl's Web Log on 8/30/2007 11:01:49 AM
I'm working on an application that's dynamically mapping requests to a variety of classes. Based on the inbound request a lookup into various meta data tables occurs and based on this string based look up data we decide which types to invoke. .NET makes it pretty easy to dynamically invoke types (and execute code) using Reflection, but finding the right methods for each of these approaches is not always so easy - there are a lot of different ways to arrive at the same operation. So here's a quic ...
by Rick Strahl via Rick Strahl's Web Log on 8/28/2007 11:46:46 PM
This probably falls into the bonehead category, but this might bite somebody else so I'm writing it up: LINQ to SQL works best when your database tables have version fields that can be used to see change state. So recluctantly I resigned myself to give in to this and decided I'd use a consistent fieldname that wouldn't interfere with normal naming. Version and TimeStamp may be very clear names, but they are also likely fieldnames that can be chosen for real field data in a table. So I decided to ...
by Rick Strahl via Rick Strahl's Web Log on 8/28/2007 7:43:01 AM
There are two things in LINQ to SQL that I've been fretting about quite a bit and it has to do with issues of getting stuck either by the possibilty of LINQ not being able to express a query and the fact that LINQ queries need to be expressed as cold, hard types that cannot easily be created dynamically. The first scenario I haven't actually run into in my experiments directly although I can see it potentially happening. LINQ is statically typed so there's a limited set of SQL features that are ...
by Rick Strahl via Rick Strahl's Web Log on 8/24/2007 10:24:26 AM
When using LINQ to SQL, it lets you retrieve entity lists as results from SQL queries. While that's usually what you would like to retrieve from LINQ query, LINQ to SQL also provides an alternative to retrieve a raw IDbCommand statement with the SQL command and all parameters set based on the query expression. This means that you can actually bypass the Entity list generation and use the query for other purposes like generating a DataReader instead: var q = from c in db.tt_customers & ...
by Rick Strahl via Rick Strahl's Web Log on 8/16/2007 7:02:33 AM
Quick, how many times will this LINQ query hit the database: Stopwatch sw = new Stopwatch();sw.Start(); NorthwindDataContext context = new NorthwindDataContext();context.ObjectTrackingEnabled = false ; var result = from c in context.Customers select c; // new { CustomerID = c.CustomerID, Company = c.CompanyName }; for (int x = 1; x < 1000; x++ ){ foreach (Customer c in result) {&n ...
by Rick Strahl via Rick Strahl's Web Log on 8/15/2007 7:17:03 AM
Several people have been flogging me for my LINQ and disconnected Entity post, so I thought I should follow up on the issues I've been having. First let me restate Entity issue I raised a couple of days ago, but let me present it in a simpler context with the Northwind database, so you can try it and experiment with this stuff yourself and those who keep telling me to RTFM can post a concrete reply <g>. The issue is this: I want to basically create an instance of an entity throug ...
by Rick Strahl via Rick Strahl's Web Log on 8/13/2007 7:02:17 PM
As I mentioned in my last post I'm trying to see how LINQ fits into a middle tier type business layer. LINQ to SQL works by providing strongly typed access through the underlying language to data objects contained in a database. But the process to get there basically requires code generation which effectively results in a static class structure. There are many advantages to this approach including type discovery, Intellisense support, compiler type checking before you run your app and the abilit ...
by Rick Strahl via Rick Strahl's Web Log on 8/13/2007 1:49:55 AM
I am playing around with LINQ to SQL in conjunction with business objects. So rather than using LINQ directly in the front end UI I want an abstraction layer. One problem that I can't seem to resolve with the data context is how to update Entities based on POCO objects that didn't originate out of the DataContext. LINQ wants to manage all objects through its data context which basically manages change tracking for any entities - any changes you make can later be persisted. That's fine if you use ...
by Rick Strahl via Rick Strahl's Web Log on 8/9/2007 8:16:36 AM
In the ResX exporter for my data driven Resource Provider I use a bit of code that iterates over the database resources and then spits out ResX resources from the data as an option to get your resources into your Web site. The code I've used in this stretch of code uses an XmlWriter to quickly spit out the data. But there are a couple of non-critical problems in that code. Several people have pointed out that the XML generated doesn't exactly match the ResX format that Visual Studio uses (althou ...
by Rick Strahl via Rick Strahl's Web Log on 8/1/2007 8:13:43 PM
I got a call from a customer last week who needed a small piece of work done that he defined as 'Trivial'. Ok, trivial can be good - quickie in and out and you're done, but usually when I hear the word trivial I always cringe because it rarely is. Not Trivial:It's an issue of perception of course and it depends on who you talk to. If you talk to a non-developer almost any sort of development seems trivial. I mean everybody does it right? We have Web pages everywhere - so it's gotta be ...
by Rick Strahl via Rick Strahl's Web Log on 7/31/2007 7:50:14 AM
Somehow, sometime ago a spambot got into my West Wind Web Store and picked up a couple of pages and decided to just POST random (and randy <s>) SPAM to this URL to the tune of a few hundred POSTs a day by now. The funny thing about this is that the URL is just a product page that accepts only a single input quantity. For example: http://www.west-wind.com/wwstore/item.aspx?sku=WWHELP40 There's absolutely no redeeming value to keep spamming this URL and posting data to it that goes abso ...
by Rick Strahl via Rick Strahl's Web Log on 7/24/2007 7:30:46 AM
In ASP.NET 2.0 ResourceProviders allow extension of the native resource mechanism with your own resource backing store by implementing a custom ResourceProvider. I've recently published an extensive article that talks about this process in detail and why this can be quite useful. One of the issues that I've been struggling with is that the ASP.NET ResourceProvider(s) are not directly accessible from your ASP.NET code. ASP.NET basically gives you access to HttpContext.GetGlobalResourceObject() an ...
by Rick Strahl via Rick Strahl's Web Log on 7/23/2007 8:30:26 AM
I ran into an interesting post on the ASP.NET forums today where someone is trying to dynamically invoke a page class inside of an HttpHandler. Basically the idea is that you have a class for the page that exist and you're dynamically invoking the class rather than letting the ASP.NET BuildManager deal with loading the page from disk and doing its thing. This can be pretty useful in a few scenarios - for example you can potentially use library projects to pre-compile ASP.NET pages completely and ...
by Rick Strahl via Rick Strahl's Web Log on 7/14/2007 10:06:33 AM
I'm looking at a piece of code that's a custom control that embeds a bit of JavaScript into a page. Part of this JavaScript is generating some static string text directly into the page. I've been running this code for a while now as part of an application I'm working on with a customer. But a couple of days ago I ran into a couple of problems with this control and as it turns out the problem is that the JavaScript strings embedded into the HTML stream aren't properly encoded. The code used is&nb ...
by Rick Strahl via Rick Strahl's Web Log on 7/10/2007 8:57:42 AM
COM Interop is rarely fun, but it looks like it's getting to be less and less useful as time goes on and new .NET Runtime features come along that don't work well over COM. It appears that Generic types can't be exported over COM and be usable to a client like Visual FoxPro. When I create a class like this: [ComVisible(true)] [ClassInterface(ClassInterfaceType.AutoDual)] public class Person { public string Name { get { return _Name; } set { ...
by Rick Strahl via Rick Strahl's Web Log on 6/29/2007 9:57:27 AM
I've talked a bit about GZip compression (here and here and here) on the server recently. It's pretty straight forward to use GZip compression either by letting IIS do it for you automatically or by using some simple ASP.NET code to compress content. As a quick review to create GZip content on the server generically I created a couple simple static utility functions that can be called from anywhere to dynamically encode dynamic ASP.NET content:/// <summary> /// Determines if GZip ...
by Rick Strahl via Rick Strahl's Web Log on 6/24/2007 7:45:18 AM
ASP.NET provides the ability to use strongly typed resources for Global resources that are contained in App_GlobalResources. This is a nice feature, but it has a pretty major flaw as it's implemented right now. The way this works is that you have your Resx file in App_GlobalResources and ASP.NET will at compile time generate a class from each of the resource sets (each distinct invariant .resx file) defined. For example a generated class looks like this:public class resources { // ...
by Rick Strahl via Rick Strahl's Web Log on 6/16/2007 6:05:56 AM
I'm still screwing around West Wind Web Connection and trying out a quick proof of concept tonight and thought I'd share a few steps on how to host a Windows Communication Foundation (WCF) Service in a COM client like Visual FoxPro. The scenario I'm playing around with is to provide another alternate messaging mechanism for West Wind Web Connection that uses WCF to pass messages between the West Wind Web Connection Connector (in this case an ASP.NET HttpModule) and a Visual FoxPro object. Y ...
by Rick Strahl via Rick Strahl's Web Log on 6/15/2007 9:43:32 AM
I've been working on replacing an ISAPI module which is a connector piece to an Application Server interface that interfaces with Visual FoxPro. In this interface the backend is managing a pool of COM objects that process requests and return results. Dealing with COM objects might seem pretty passee in the age of .NET but nevertheless there's still a lot of that going around and I'm quite involved with this due to my FoxPro background and FoxPro's one interface mechanism to .NET being through CO ...
by Rick Strahl via Rick Strahl's Web Log on 6/8/2007 2:28:39 AM
I don't know about you, but I cringe every time I need to create a GridView based layout that needs to create a few custom link handlers off that grid. The typical scenario might be a list where you can toggle certain options or where you can fire an operation that otherwise updates the data that's underlying the grid. I tend to use business objects in my applications so using the standard data controls doesn't work very well, nor would it really buy much in terms of abstraction. In my code I te ...
by Rick Strahl via Rick Strahl's Web Log on 5/24/2007 4:59:30 AM
Here's a fun one to do in WPF. Say you have a ListBox or ListView that is databound and you want to get at the content of the data template used for binding of the items in the list. In my case I want to trigger an animation when the item is selected to indicate the change. It's quite easy to get a selected item from a list box: // *** Bound item - ie. an XmlNode/XmlElement XmlElement item = this.lstPhotos.SelectedItem as XmlElement; if (item == null) return; This assum ...
by Rick Strahl via Rick Strahl's Web Log on 5/21/2007 4:08:20 AM
So I spent the evening today experimenting with databinding in WPF. Overall I'm very excited about that data binding capabilities in WPF which finally has produced a powerful and reasonably user friendly way to do data binding of just about any type to anything else. WPF makes this easily available courtesy of dependency properties which can automatically manage their change tracking and two-way updating of bindings. FWIW, what I'm writing about here is sort of along the 101 getting started path ...
by Rick Strahl via Rick Strahl's Web Log on 5/17/2007 6:14:12 AM
I took a little bit of time today to make a few minor changes to the blog here and added some enhancements to the comments section here. One of the additions is support for Gravatars which is a very simple REST based mechanism that lets you show an avatar image. Gravatar is implemented by quite a few sites these days (SubText, DasBlog and Community Server all support it for example), so if you access any of these sites you can get your image shown on those sites. This is nothing new really (espe ...
by Rick Strahl via Rick Strahl's Web Log on 5/15/2007 6:14:34 AM
Ok so I had a little free time on my hands this weekend and was looking for a simple something to use WPF on. A few weeks back I'd been playing with an Justin Brown's Amazon book plug in for Live Writer, which is part of the Windows Live Writer Plugins on CodePlex. Back when I first looked at his plug-in which is great, I added a few small enhancements like configuration of the Amazon Service and Associate ID and a few minor changes in the way the pop up window and resulting HTML formatting work ...
by Rick Strahl via Rick Strahl's Web Log on 5/14/2007 5:40:27 AM
I'm experimenting with DynamicMethod in .NET 2.0 in light of all the good things that apparently have come of it especially in light of the recent release of the Dynamic Language Runtime on CodePlex. I haven't dug into that code (I suspect it won't be light reading <s>), but thought it sure would be nice to have a more dynamic execution mechanism that can take arbitrary code and execute it. I would love to have the functionality to dynamically create a block of code and execute it as part ...
by Rick Strahl via Rick Strahl's Web Log on 5/10/2007 7:59:44 AM
This post in the 'stupid pet tricks' category I suppose - it's not one of the things that you need to do every day, but if you need to run an application that requires that your ASP.NET application stays up and running without the discontinuity of AppDomain or worker process shutdowns this can be useful. First some background on the scenario. I'm working on a small project for a customer that deals with a background scheduler that's running continuously and checks the contents of a POP3 box at i ...
by Rick Strahl via Rick Strahl's Web Log on 4/30/2007 8:58:54 AM
You ever do this stunt? You're in the middle of working and you realize that you need a string function. .NET makes string manipulation fairly easy but it can often be frustrating to find just the right function. The issue is that .NET string functions are scattered over several different objects. The string class is what is used most frequently but it's not a terrible complete set of string manipulation functions. So I just needed a routine to replace the 2nd instance of a particular string mat ...
by via Rick Strahl's Web Log on 4/19/2007 5:31:37 AM
I just had a little brain freeze dealing with an HRESULT error from a COMException. When dealing with COM objects you still need to deal with the unfortunate COM idiosyncrasies like HRESULT values which get returned from just about every COM call. COMException exposes this HRESULT as an int value in the Exception's ErrorCode property. Now in my brain freeze haze I tried something like this: try{ this.OutputBuffer = this.ComInstance.GetType().InvokeMember("ProcessHit", Bind ...
by Rick Strahl via Rick Strahl's Web Log on 4/12/2007 12:14:45 PM
by Rick Strahl via Rick Strahl's Web Log on 4/12/2007 2:13:31 AM
So for the last few days I've been going through the final steps of updating Html Help Builder to properly run under Windows Vista without any file permissions, registry or other sort of elevation requirements. In theory the application should run fine after installation without any sort of crutch like Folder Virtualization. Some may snicker and say - "What took you so long; Windows guidelines have been saying that for years". You know don't store data in Program Files, use a Documents folder fo ...
by Rick Strahl via Rick Strahl's Web Log on 4/6/2007 9:46:53 PM
In Html Help Builder's documentation imports from .NET code I have to manage two sets of interfaces: One that imports data using Reflection which is the more thourough mechanism that goes out, parses types and pulls in XML documentation. Getting Generics to work right in that code took a while to get right, but it's been working for some time. The other end of things is the CodeDom side in the VS Editor. In Html Help Builder you can do two-way comment editing where you can sit on a method in cod ...
by via Rick Strahl's Web Log on 4/6/2007 8:09:39 AM
Ran into an interesting question on the ASP.NET newsgroup today regarding a problem I've run into a few times myself. The issue revolves around virtual directory folder inheritance and web.config settings getting inherited from a root Web site. Anyway - one issue that has come up a few times is that the root site defines an HTTP module. The child virtual (an off the root virtual directory) when created by default inherits that module entry in web.config and usually fails because the module isn't ...
by Rick Strahl via Rick Strahl's Web Log on 4/2/2007 10:13:46 PM
I mentioned a few days ago that I was working on a Web application that's dealing with custom extensions to route requests to a very large number of custom 'script' pages. Basically I have a custom IHttpHandler based base class and custom subclasses that implement the actual handler logic which is essentially a script like implementation to call business objects and return an XML response to the client. I love using HttpHandlers in general because of the high performance and simple imp ...
by via Rick Strahl's Web Log on 3/28/2007 2:01:26 AM
I'm working on an application that's using custom HTTP handlers to handle inbound Web requests where each script request is pointing at an HTTP handler. In this case the handlers need to be individual files so I have a script map configured in IIS with a special extension and then mapped to my virtual directory. So the idea is that I can use a script call like this: ScriptHandler.xrns To make this work the xrns script extension must be mapped in IIS to the ASPNET_ISAPI.DLL (in classic ASP.NET mo ...
by Rick Strahl via Rick Strahl's Web Log on 3/22/2007 8:03:06 AM
I've been mostly watching LINQ take shape and only recently started in looking at it a bit more closely.I've been pretty excited about the prospect of LINQ in general and the database connectivity in particular - after all I come from an XBase background where a built in Data Definition Language and native SQL syntax has always been available (for 20 years!). LINQ of course is much more than just the data access layer and to be honest the language integration features are much more impressive t ...
by via Rick Strahl's Web Log on 3/21/2007 3:30:08 AM
I often find myself using various collection types for 'cached' storage in Web applications. For example, in some applications there are lists of countries, lists of states, various other lookup lists that are initially stored in a database, but then are constantly reused. There's little point in continually reloading this data from the database so caching it as part of the application is useful. Depending on how you like to work data is usually pulled from the database with a DataReader, ...
by via Rick Strahl's Web Log on 3/19/2007 7:35:22 AM
I spent a few hours a couple of days ago creating a plugin for Windows Live Writer that allows for easy screen captures. I've long been a huge fan of SnagIt from Techsmith and since SnagIt's capture functionality is available as a COM interface it's quite easy to expose the functionality in other applications. For example, I have SnagIt plugged into my Help Builder tool to provide for screen captures in the Help HTML content. Blogging is kind of similar: image capturing is pretty vital and ...
by Rick Strahl via Rick Strahl's Web Log on 3/18/2007 12:22:34 PM
by Rick Strahl via Rick Strahl's Web Log on 3/17/2007 7:15:06 AM
I'm working on a plug in for LiveWriter that does screen captures with SnagIt and embeds the content directly into the post. Works great, but now I'm to the point that I want to set up some configuration options and serialize them. I use a few simplified serialization functions in my utility library that make serialization a one line method call and usually this works great. Here's what the Serialization code to the registry looks like: /// <summary>/// Saves the current settings of this o ...
by Rick Strahl via Rick Strahl's Web Log on 3/3/2007 10:52:50 AM
So for the last few days or so I’ve been playing around with WPF/E on the side. Mainly looking at samples, reading through code and setting up some simple examples for myself to get through the conceptual process. The idea of having a rich, and light weight client platform that can run in the browser has always been very enticing and WPF/E sounds like it might address that scenario – or some of that scenario. WPF/E is a small subset of the full WPF (Windows Presentation Framework) and is ...
by via Rick Strahl's Web Log on 2/24/2007 6:32:00 AM
I’ve been struggling over the last few days with an application that is using the ASP.NET cache quite bit. As it turns out the programmatic cache in ASP.NET in most of my applications is not keeping items in them under almost all circumstances. When I’m talking about the programmatic cache, I mean the Context.Cache object and manually adding items into the cache. I’m a big fan of HTML fragment caching for rendering portions of a page either via code based rendering or from control b ...
by via Rick Strahl's Web Log on 2/14/2007 8:10:14 AM
As was going through my JSON Serialization code the other day I kept re-thinking this idea I had some time ago: Why not use Microsoft’s built in JavaScript engine to perform the JavaScript and JSON deserialization. After all there is an official Microsoft JavaScript .NET language and it should be possible to take advantage of this from within an application. I finally had some time to check this out... I started searching for how to do this and there’s not a heck of a lot of information ...
by via Rick Strahl's Web Log on 2/7/2007 8:56:11 AM
Here’s a nice baffler that’s been giving me fits for about an hour now. Check out this debugger highlight: I’m running into this situation where a field up the inheritance structure will simply not set. In this case the _IsEntityDirty field was just assigned a value of true, yet the debugger (and not just the debugger – conditional code actually sees this value as false!) sees the value as false. Note this is a protected field defined 2 levels up the hierarchy. I can’t ...
by Rick Strahl via Rick Strahl's Web Log on 2/7/2007 8:56:11 AM
by Rick Strahl via Rick Strahl's Web Log on 2/6/2007 12:53:22 AM
After I posted the GZip Script Compression module code a while back, I’ve gotten a number of questions regarding GZip and compression in ASP.NET applications so I thought I show a couple of other ways you can use the new GZipStream class in ASP.NET. The beauty of this new GZip support is how easy it is to use in your own ASP.NET code. I use the GZip functionality a bit in my WebLog code. For example the the cached RSS feed is GZip encoded which uses GZipStream on the Response.OutputStream fed to ...
by via Rick Strahl's Web Log on 2/6/2007 12:53:22 AM
by via Rick Strahl's Web Log on 2/4/2007 10:07:50 AM
UTF-8 with an XmlWriter (or even HtmlTextWriter for that matter) can sometimes be tricky if you’re sending output back into anything but a file. If you write data to a string or data to a stream that gets immediately fed into an output stream in a Web application or a POST buffer for an HTTP request you might find that the formatting of the XML generated usually will blow up. Typically you have code like this: MemoryStream ms = new MemoryStream(); &nbs ...
by Rick Strahl via Rick Strahl's Web Log on 2/4/2007 10:07:50 AM
by via Rick Strahl's Web Log on 2/1/2007 10:27:35 AM
I ran into a problem with Serialization today in one of my utility classes. I have an Entity generator tool I use that generates entity classes for my business objects from the database. One of the things I do in the generated file is embed the settings of the object as an embedded XML Serialization XML string right into the generated code and bracket it with #if false/#endif. I can then simply point the tool right back at this file and it can pick up the settings directly out of the generated ...
by Rick Strahl via Rick Strahl's Web Log on 2/1/2007 10:27:35 AM
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.