KBD

Keith Devens .com

Sunday, March 21, 2010 Flag waving
It's such a fine line between stupid and clever. – David St. Hubbins (This is Spinal Tap)

Tag: .NET

Parents:

Children:

Page 1 →

Daily link icon Sunday, November 9, 2008

  1. ASP.NET UI and Charting Controls by ComponentArt.

       (0) Tags: [ASP.NET]

Daily link icon Monday, October 6, 2008

  1. Easily refresh an UpdatePanel, using JavaScript | Encosia.

       (0) Tags: [ASP.NET]

Daily link icon Monday, September 22, 2008

  1. Why ASP.NET AJAX UpdatePanels are dangerous | Encosia. PageMethods, neato. No reason to use Prototype, etc. with ASP.NET.

       (0) Tags: [ASP.NET]

Daily link icon Friday, September 12, 2008

  1. obout inc appears to have some high-quality ASP.NET controls.

       (2) Tags: [ASP.NET]

Daily link icon Tuesday, September 9, 2008

  1. Binary Fortress Software |  ASP.NET ViewState Helper (via).

       (0) Tags: [ASP.NET]
  2. TreeView control stuff:

       (0) Tags: [ASP.NET]

Daily link icon Tuesday, September 2, 2008

Hating ASP.NET again

The more I use ASP.NET, the more I can't stand it. I'm using the ASP.NET Ajax stuff and it'd be so much faster if I just did everything "manually" rather than navigating this maze of UpdatePanels and RegisterClientScriptBlocks and AsyncPostBackTriggers.

Web apps are just XmlHttpRequest + some JSON and CSS and DOM manipulation. I already know all that stuff. Why does Microsoft fail so hard at simplification that they make it more complex?

Daily link icon Monday, June 23, 2008

  1. Jayrock: JSON and JSON-RPC for .NET.

       (0) Tags: [ASP.NET, Json]

Daily link icon Friday, January 18, 2008

  1. 15 Seconds : Tuning Up ADO.NET Connection Pooling in ASP.NET Applications.

       (0) Tags: [ASP.NET]

Daily link icon Friday, January 11, 2008

  1. ASP.NET AJAX Control Toolkit.

       (2) Tags: [ASP.NET, Javascript]

Daily link icon Tuesday, July 24, 2007

  1. John Lam on Software: A first look at IronRuby. To read.

       (0) Tags: [IronRuby]

Daily link icon Friday, February 23, 2007

  1. How To Copy DataRows Between DataTables by Using Visual C# .NET:

    Before you use the ImportRow method, you must ensure that the target table has the identical structure as the source table. This sample uses the Clone method of DataTable class to copy the structure of the DataTable, including all DataTable schemas, relations, and constraints.

       (0) Tags: [.NET]

Daily link icon Friday, February 2, 2007

  1. Ruby/.NET Bridge.

       (0) Tags: [.NET, Ruby]

Daily link icon Wednesday, November 8, 2006

  1. IronPython. The official home page of IronPython. Google is out of date.

       (0) Tags: [IronPython]

Daily link icon Wednesday, August 30, 2006

Json.NET - Newtonsoft

Json.NET - Newtonsoft, a C# implementation of JSON. Looks really good from their example... about to try it out.

Update: based on testing so far, it works great. Their example output is incorrect however. It uses single quotes, when only double quotes are allowed in JSON. But the code in fact does the right thing.

Note that the library will generate invalid JSON and include language-specific types in it, such as a date. And that's actually desirable, since if you're just using it as serialization for your own code you get what you want, and can be careful and not use language-specific types if you need to share with others.

Daily link icon Thursday, June 22, 2006

  1. String.IsNullOrEmpty can lead to runtime Null exceptions (via Adam). Nice.

       (0) Tags: [.NET]

Daily link icon Thursday, June 8, 2006

  1. Geekpedia • ASP.NET: The name 'Session' does not exist in the current context. I think this'll happen in particular if you're trying to access Session from a class defined in App_Code. Use HttpContext.Current.Session instead.

       (3) Tags: [ASP.NET]

Daily link icon Wednesday, June 7, 2006

  1. PageMethods, well-defined URLs for your ASP.NET sites by metaSapiens. Looks pretty neat. It seems to work something like the URI to object method call frameworks that exist for other languages.

       (0) Tags: [ASP.NET]

Daily link icon Tuesday, May 2, 2006

  1. MonoRail:

    MonoRail (former Castle on Rails) is a MVC web framework inspired on Action Pack. The Action Pack way of development is extremely productive, very intuitive and easily testable.

    MonoRail differs from the standard WebForms way of development as it enforces separation of concerns; controllers just handle application flow, models represent the data, and the view is just concerned about presentation logic. Consequently, you write less code and end up with a more maintainable application.

       (0) Tags: [ASP.NET, Ruby on Rails]
  2. Cassini Web Server - Free Redistributable ASP.NET Web Server from UltiDev LLC.

       (0) Tags: [ASP.NET]

Daily link icon Monday, April 17, 2006

How to do clean URIs in your ASP.NET application

It's actually very simple to do clean URIs in an ASP.NET application. In your Global.asax file:

string root = "/rootofyourapp";

void Application_Start(object sender, EventArgs e){
    Dictionary<string,string> mapping = new Dictionary<string,string>();
    mapping[root+"/page"]=root+"/page.aspx";
    Application.Add("mapping",mapping);
}

void Application_BeginRequest(object sender, EventArgs e){
    HttpContext context = HttpContext.Current;
    string path = context.Request.Path;
    Dictionary<string,string> mapping =
        (Dictionary<string,string>)Application["mapping"];
    
    if(mapping.ContainsKey(path)){
        context.RewritePath(mapping[path]);
    }else{
        Response.AddHeader("Content-type","text/plain;charset=UTF-8");
        Response.Write("Invalid request: "+path+"\n\n");
        Response.End();
    }
}

And to forward all requests through to a single URI:

void Application_BeginRequest(object sender, EventArgs e){
    HttpContext.Current.RewritePath("~/Default.aspx");
}
  1. MySpace does 1.5 billion page views per day using ASP.NET 2.0. They just switched from ColdFusion, a Java based technology, and their server load went down dramatically. Of course it's not surprising that switching from Java would make your app run faster, but what makes this so ironic is that they're still largely using ColdFusion, but using a .NET-based reimplementation called BlueDragon. So, a .NET-based reimplementation of ColdFusion runs dramatically faster than the original Java-based implementation.

       (2) Tags: [.NET, ColdFusion, Java]

Daily link icon Friday, April 14, 2006

  1. ViewState Decoder (2.1) by Fritz Onion. Also see this article by Paul Wilson (who apparently used to have a similar tool online that's no longer available) about ASP.NET's viewstate process (to read).

       (0) Tags: [ASP.NET]

Daily link icon Tuesday, April 4, 2006

Pretty-print .NET objects?

Does anyone know of a way to pretty-print .NET objects? We've covered before how .NET objects don't stringify into anything good, so I'm looking for a pretty-printer to aid in debugging. .NET has such good reflection that I'm surprised I can't find a pre-existing library or built-in .NET facility. Do I have to take a half hour and write my own pretty-printer?

Update (2:29pm): There we go, this only took me about 20 minutes:

using System;
using System.Text;
using System.Reflection;

class foobar{
    string foo, bar, baz;
    bar b = new bar();
}
class bar{
    string roar, blah;
}

namespace PrettyPrinter{
    public class PrettyPrinter{
        public static void Main(string[] args){
            foobar f = new foobar();
            Console.WriteLine(pp(f));
            int i = 2;
            Console.WriteLine(pp(i));
        }
        public static string pp(object o){
            StringBuilder sb = new StringBuilder();
            pp(sb, o, 0);
            return sb.ToString();
        }
        public static void pp(StringBuilder sb, object o, int level){
            Type t = o.GetType();
            FieldInfo[] members = t.GetFields(
                        BindingFlags.Public
                        | BindingFlags.NonPublic
                        | BindingFlags.Instance
            );

            foreach(FieldInfo info in members){
                object val = info.GetValue(o);
                sb.Append('\t',level);
                sb.Append(info.ToString()).Append(": ");
                if(val == null){
                    sb.AppendLine("null");
                }else if(info.FieldType.IsClass){
                    sb.AppendLine("{");
                    pp(sb, val, level+1);
                    sb.Append('\t',level).AppendLine("}");
                }else{
                    sb.AppendLine(o.ToString());
                }
            }
        }
    }
}

Output:

C:\DEV\Projects\test\bin\Debug>test
System.String foo: null
System.String bar: null
System.String baz: null
bar b: {
        System.String roar: null
        System.String blah: null
}

Int32 m_value: 2

Update (4:57pm): Since of course that was a first pass, here's a more correct version that handles circular references, and for Keith also dumps XML if you happen to pass it an XmlNode Smiley

using System;
using System.Xml;
using System.Text;
using System.Reflection;
using System.Collections.Generic;
using pp = PrettyPrinter.PrettyPrinter;

namespace PrettyPrinter{
    public class PrettyPrinter{
        private static Type str = typeof(string);
        private static Type xml = typeof(XmlNode);

        public static string pp(object o){
            if(o == null)
                return "null";

            StringBuilder sb = new StringBuilder();
            sb.Append(o.GetType()).Append(": ");
            pp(new Dictionary<object, bool>(), sb, o, 0);
            return sb.ToString();
        }

        public static void pp(
                Dictionary<object, bool> seen_objects,
                StringBuilder sb, object o, int level
        ){
            Type t = o.GetType();
            if(t == str || t.IsValueType){
                sb.AppendLine(o.ToString());
            }else if(xml.IsInstanceOfType(o)){
                sb.AppendLine(((XmlNode)o).OuterXml);
            }else if(t.IsClass){
                if(seen_objects.ContainsKey(o)){
                    sb.AppendLine("RECURSION!");
                    return;
                }
                seen_objects.Add(o, true);
                FieldInfo[] fields = t.GetFields(
                    BindingFlags.Public
                    | BindingFlags.NonPublic
                    | BindingFlags.Instance
                );
                sb.AppendLine("{");
                foreach(FieldInfo info in fields){
                    object val = info.GetValue(o);
                    sb.Append('\t',level+1).Append(info).Append(": ");
                    if(val == null){
                        sb.AppendLine("null");
                    }else{
                        pp(seen_objects, sb, val, level+1);
                    }
                }
                sb.Append('\t',level).AppendLine("}");
            }
        }
    }
}

class foobar{
    string foo, bar, baz = "roar";
    public testing.bar b = new testing.bar();
}

namespace testing{
    class bar{
        string roar, blah;
        public foobar f;
    }
    class baz{
        public baz b = null;
    }
}

public class Test{
    public static void Main(string[] args){
        foobar f = new foobar();
        f.b.f = f;
        Console.WriteLine(pp.pp(f));

        int i = 2;
        Console.WriteLine(pp.pp(i));

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(@"<?xml version=""1.0""?>
            <foo><bar><baz>roar</baz></bar></foo>"
        );
        Console.WriteLine(pp.pp(doc.ChildNodes[1]));

        testing.baz b = new testing.baz();
        b.b = b;
        Console.WriteLine(pp.pp(b));
    }
}

Output:

C:\DEV\Projects\test\bin\Debug>test
foobar: {
        System.String foo: null
        System.String bar: null
        System.String baz: roar
        testing.bar b: {
                System.String roar: null
                System.String blah: null
                foobar f: RECURSION!
        }
}

System.Int32: 2

System.Xml.XmlElement: <foo><bar><baz>roar</baz></bar></foo>

testing.baz: {
        testing.baz b: RECURSION!
}

(code reformatted to not break my layout)

Daily link icon Monday, April 3, 2006

  1. Mike Stall's .NET Debugging Blog : How to embed IronPython script support in your existing app in 10 easy steps. I don't agree with everything he did here, but it's a darn useful reference and introduction, and he has some neat tricks.

       (0) Tags: [IronPython]

Daily link icon Friday, March 24, 2006

.NET standard library has holes

The .NET standard library is good, but it feels like it has lots of "holes" in it, even in 2.0. For instance, why is the Converter delegate used separately on Array's and List's ConvertAll rather than being defined on a Collection or an Enumerable so that I could use ConvertAll on things like Dictionary.KeyCollection? The answer, of course, is that Collection and Enumerable are actually ICollection and IEnumerable and are not classes.

So, Microsoft didn't choose to duplicate ConvertAll everywhere it'd be useful, just in a couple of places. What this means as well is that even though you can use a foreach loop on something, you can't necessarily do a ConvertAll on it (or use the other higher-order methods). In contrast, look at Ruby, where as long as you have an each method (IIRC), you get everything associated with it for free.

Also see Adam's description of GetValue and SetValue on properties and accessors, another case where Microsoft has the same method names for similar functionality on multiple classes but no common interface or base class between them, so they can't be used interchangeably. (Insert comment about the utility of duck-typing here...)

As an aside, I also feel like it's just darn hard to find things reliably in Microsoft's documentation.

Daily link icon Saturday, March 18, 2006

  1. ASP.NET 2.0 Training Center: Cross Training for Web Developers:

    This section of the ASP.NET 2.0 Training Center helps the PHP developer learn more about PHP, and also add to their skillset by mastering ASP.NET 2.0. In the coming weeks, you'll learn how to get up to speed with ASP.NET 2.0, and you'll find details about interoperability between PHP and ASP.NET 2.0.

    To help you, you'll also find a series of webcasts specifically created, from the ground up, by world-class experts and presenters to teach ASP.NET to PHP developers.

    Started reading the first article on the page and it's excellent so far.

       (0) Tags: [ASP.NET, PHP]

Daily link icon Thursday, February 23, 2006

TableAdapter vs DataAdapter

If you're not sure whether to use a TableAdapter or a DataAdapter, this tells you which one you should use:

The typical Visual Studio mechanism for executing Transact-SQL queries and for filling datasets is the TableAdapter.

You can execute SQL statements or stored procedures against a data source using TableAdapters or command objects (for example, SqlCommand). To load data into datasets created using design tools in Visual Studio, use TableAdapters. To load data into datasets created programmatically, use data adapters. If your application does not use datasets, use command objects to execute SQL statements or stored procedures directly against a database.

If you create a dataset with a Visual Studio design-time tool (such as the Dataset Designer or the Data Source Configuration Wizard), then you use a TableAdapter to fill it. TableAdapters execute your SQL statements or stored procedures.

If you create a dataset without design-time tools, then you must use data adapters to fill and update data. (TableAdapters are not actual classes in the .NET Framework, so they are not suitable for working with datasets that have been created without the use of design-time tools. For more information on loading data into datasets with either TableAdapters or data adapters, see How to: Fill a Dataset with Data.

Daily link icon Wednesday, February 22, 2006

  1. Brad Abrams: The change from Hashtable to Dictionary.

       (0) Tags: [.NET, C#]
Page 1 →
March 2010
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 3 posts

Recent comments XML

new⇒Spider solitaire

I to am somewhat addicted to​spending too much time on SS.  I​have been stu...

stupid_horse: Mar 20, 10:34pm

I hate ASP.NET

I hate ASP... I was doing wonders​with PHP, then suddenly one of my​clients...

Johnies: Mar 17, 6:14am

Quantum physics and free will

I knew you were going to say that....

Tom Massey: Mar 15, 9:26pm

Generated in about 0.173s.

(Used 11 db queries)