ASP.NET MVC 1.0 Final Release

by Sander Gerz March 18, 2009 17:00

I will certainly not be the first, nor the last, but here it is. ASP.NET MVC 1.0 final version is released.

Download ASP.NET MVC 1.0 here.

Currently rated 3.2 by 9 people

  • Currently 3.222222/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Javascript compressing and more

by Sander Gerz March 17, 2009 09:14

Guillermo writes about a website that can compress javascript files. It does a really good job, but when I downloaded the result, it was unreadable.

O="functioresultarkervar conercatch(    windowoundstionif(atTemp uetails r){}eh
 

Would a browser still understand what to do? Well, it certainly did. Just make sure that you need to define the charset for the script:

   1: <script src="[yourscript]" type="text/javascript" 
   2:     charset="ISO-8859-1" ></script>
 
So not only is your javascript compressed, it’s also obfuscated in such a way that others cannot easily see what it’s doing or make modifications for their own purpose.

Currently rated 2.7 by 7 people

  • Currently 2.714286/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Migration to BlogEngine.NET

by Sander Gerz March 16, 2009 19:06

It was about time I migrated my weblog, based on .Text version 0.95 to a more modern blogging platform. As you will probably know, the codebase of .Text was integrated to Community Server ages ago. I doubt whether much of that original code is still alive in CS, if any at all.

Anyway, both BlogEngine.NET and dasBlog seemed like good alternatives. Subtext too. I decided to go with BlogEngine.NET. It’s not that I did extensive research on all the options, as long I was able to migrate the content and use Live Writer for posting. A post by Erik Lane helped me through it. He also posts instructions on how to keep old links working. I didn’t want to mess in the code of BlogEngine.NET, so after updating the BE.NET database, I just added the following hack to global.asax:

    protected void Application_BeginRequest(object sender, EventArgs e)

    {  

        HttpContext context = HttpContext.Current;

       

        // Handle .Text rss feed requests.

        if (context.Request.Url.PathAndQuery.ToLower().Contains("/rss.aspx"))

        {

            context.Response.Redirect("syndication.axd", false);

            context.Response.StatusCode = 301;

            context.Response.End();

        }

       

        // Handle .Text requests from archived posts

        if (context.Request.Url.PathAndQuery.Contains("/archive/"))

        {

            // lookup post

            int dotTextPostId = GetPostId(context.Request.Url.PathAndQuery);

            System.Collections.Generic.Dictionary<int, string> posts = GetPosts();

 

            string relativeLink = string.Empty;

            if (posts.ContainsKey(dotTextPostId))

                relativeLink = posts[dotTextPostId];

               

            string redirUrl = string.Format("{0}://{1}{2}",

context.Request.Url.Scheme, context.Request.Url.Authority,

relativeLink);           

            context.Response.Redirect(redirUrl, false);

            context.Response.StatusCode = 301;

            context.Response.End();

        }

    }

 

    private static readonly Regex DOTTEXT =

new Regex(@"/archive/\d{4}/\d{2}/\d{2}/(?<postId>\d+)\.aspx$",

        RegexOptions.IgnoreCase | RegexOptions.Compiled);

 

    private int GetPostId(string url)

    {

        Match match = DOTTEXT.Match(url);

        if (match.Groups.Count > 0)

        {

            int postId;

            if (int.TryParse(match.Groups["postId"].ToString(), out postId))

            {

                return postId;

            }

        }

        return 0;

    }

   

    // Retrieve a list of old posts, cache the result

    protected System.Collections.Generic.Dictionary<int, string> GetPosts()

    {

        System.Collections.Generic.Dictionary<int, string> posts =

HttpContext.Current.Cache["posts"] as

            System.Collections.Generic.Dictionary<int, string>;

        if (posts != null) return posts;

       

        posts = new System.Collections.Generic.Dictionary<int, string>();

 

        string query =

"SELECT PostID, DottextPostID FROM be_Posts WHERE DottextPostID IS NOT NULL";

       

        System.Data.SqlClient.SqlDataAdapter sqlDa =

            new System.Data.SqlClient.SqlDataAdapter(query,

            ConfigurationManager.ConnectionStrings["BlogEngine"].ConnectionString);

 

        System.Data.DataTable postTable = new System.Data.DataTable();

        sqlDa.Fill(postTable);

        foreach (System.Data.DataRow item in postTable.Rows)

        {

            Post p = Post.GetPost((Guid)item["PostID"]);

            posts.Add(int.Parse(item["DottextPostID"].ToString()), p.RelativeLink);

        }

 

        HttpContext.Current.Cache.Add("posts", posts, null, DateTime.MaxValue,

Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);

        return posts;

    }

It may not be the most well-designed code, but it does the trick.

Currently rated 3.1 by 9 people

  • Currently 3.111111/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen | Modified by Mooglegiant