Posts

Showing posts with the label MVC

How to convert SVG data to a Png Image file Using InkScape

Image
Introduction The project required the need to put the visual pie chart on a web page on the client and in a Pdf file created on the server. I eventually choose to use a Telerik Kendo DataViz Chart control on the client, and use a PNG file on the server for the Pdf file. This blog post will explain the process and code to convert the client-side pie chart Svg data to a Png file, and provide a download to the working code. Prerequisites You need to have a trial version of the Telerik Kendo library installed in order to make the sample code work. You also need InkScape installed. InkScape is the application that does the actual conversion. You will need to change the Web.config appSetting of “ExeDirectoryForInkscape” to represent your own installation location. Any SVG Data Will Work The pie chart was created using the Telerik Kendo DataViz chart control. While I name a specific control, as long as you have access to the SVG data, the same conversion process on the server will...

Restyling an Html <SELECT> Element from a Telerik Kendo Panel Bar

Image
Introduction Recently, I needed to restyle an HTML <SELECT> box so that the selected element had a different background color. In all other ways, the element could be exactly like an HTML <SELECT>. Below are both the original element, and the restyled element.     This type of style change allows the novice user to immediately identify the control’s implied usage while allowing for some coordination with the site and page’s overall style.   Technology Platform The project is an Asp.net MVC site with jQuery, and Knockout.js on the front-end requesting json content on the backend. For the purposes of this blog post, I’ve stripped down the functionality so that just the required elements are visible. The project was already using Telerik Kendo controls so morphing the Kendo Panel Bar into a <SELECT> element was suggested. The main work is in the css file but the entire working sample project is available for download.   Telerik ...

Results of .Net Developer’s 5 weeks with Ruby (RoR) and SaaS

Introduction Several things happened in a short period of time to influence my decision to take a Ruby/SaaS class. I’m a lifer on .Net or more specifically Asp.Net and it’s precursor, Asp. First, the MVC .Net book I was reading at the time said programmers either use .Net or Ruby for MVC development but not both. Second, an online UC Berkeley class was free and gave me both a new language ( Ruby ) and backfilled any software-as-a-service (SaaS) holes in my knowledge. Third, the class used the Agile methodology which I had bits and pieces of. I wanted to see someone else’s interpretation put into practice.   Ruby on Rails (RoR)/MVC I knew MVC , web protocols, and web development so the learning curve was all Ruby. The class had a quick pace where I knew how to do it in .Net but not Ruby. Ruby, fortunately, is a very easy language to pick up. It feels very much like a script kiddie toy but  more powerful.   Interpreted versus Compiled Ruby is interpreted w...

Combining Multiple Azure Worker Roles into an Azure Web Role

Image
Introduction While working on apps.berryintl.com ’s web service, it appeared from the Windows Azure project templates that I might need several worker roles because they cycle at different times. One worker needed to cycle every day. The other needed to cycle every five minutes. Since the work and the cycle rate were very different, it felt “right” to isolate each role. In this post, I’ll show you how I combined multiple worker roles into a single, underutilized Azure web role thereby keeping the concept and design of worker roles while not having to pay extra for them. In order to verify the solution, the project uses Azure Diagnostics Trace statements. The solution file is available for download . Combining Multiple Azure Worker Roles into an Azure Web Role Currently, I use a small Azure instance and there isn’t enough traffic to justify a separate worker role. I implemented Wayne ’s process for combining one worker role with a web role a while back. Now I needed to add anot...

Update To MVC's LogOnUserControl.ascx

Microsoft has this code for the LogOnUserControl.ascx partial control when you create a brand new ASP.NET MVC application: <%@ Control Language= "C#" Inherits= "System.Web.Mvc.ViewUserControl" %> <% if (Request.IsAuthenticated) { %> Welcome <b><%= Html.Encode(Page.User.Identity.Name) %></b>! [ <%= Html.ActionLink( "Log Off" , "LogOff" , "Account" ) %> ] <% } else { %> [ <%= Html.ActionLink( "Log On" , "LogOn" , "Account" ) %> ] <% } %> However, this isn't 100% correct. It just so happens that Page.User.Identity.Name in their example is the User's name, however really Page.User.Identity.Name in most cases is a unique (primary) key to a users table. This is a little cleaner: <%@ Control Language= "C#" Inherits= "System.Web.Mvc.ViewUserControl" %> <% if (Request.Is...

Not That Obvious In MVC

I am working on converting some ASP.NET WebForms pages into MVC Views and there are a couple of things I have run across in MasterPages that are not obvious in the beginning. With ASP.NET WebForms if you wanted dynamic content in your MasterPage one way to do it is to have the code behind of the MasterPage insert it, which means that your Page either need to tell the Master Page what to insert or the Master Page need to figure it out. Take this for example: < head > < meta name ="Description" content ="" id ="metaDescription" runat ="server" /> </ head > Here I am trying to add a meta description the head of the HTML so that the search engines know what this page is about. What I was doing is have the page check the type of the master class on the pages OnInit event and if it was the right master class, find the public property in the MasterPage that would set the MetaDescription. When the MasterPage pre-rende...

Upgrading WebForms .csproj to MVC

So you followed all the steps to upgrade your old ASP.NET WebForms project to ASP.NET MVC: added the necessary entries to the web.config, created a Views and Controllers directory, and added the necessary references. However, when you right click to add a new item to the Controllers directory (or Views directory) in Visual Studio 2008 there are no MVC items available. You need to update the .csproj view a text editor to "tell" it that it is a MVC project. Here is how: 1. Close out of Visual Studio. 2. Open .csproj file of the web site in notepad 3. In the beginning of file there is PropertyGroup block. Find the ProjectTypeGuids tag. 4. Add {603c0e0b-db56-11dc-be95-000d561079b0} as first project type GUID, the delimiter is a semi-colon. 5. Save the file . Now you can open the solution again in Visual Studio 2008 and you will have the MVC items. {6230289B-5BEE-409e-932A-2F01FA407A92}

Update To RegExRoute Class

Update with a few new constructors that allow you to use the MvcRouteHandler, and some bug fixes. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.Routing; using System.Web.Mvc; using System.Text.RegularExpressions; namespace WebUtility { public class RegexRoute : RouteBase { public Regex Regex { get; private set; } public String[] Groups { get; private set; } private IRouteHandler RouteHandler { get; set; } public String Controller { get; private set; } public String Action { get; private set; } /// <summary> /// Creates A Regular Expression Route /// </summary> /// <param name="regex">Regular Expression To Use Against /// the AbsolutePath of the request.</param> /// <param name="groups">roups In The Match</param> /// <param name="routeHa...

Application_Start Only Once

Quick note about Application_Start that I noticed when working with ASP.NET MVC. It gets called only once. Which makes total sense, since the application only starts once. However, it gets run only once even if there is an exception thrown from the code within Application_Start. Which means if RegisterRoutes throws an exception, then you need to trigger the application to reset, otherwise your routes will not be registered on the next call. For Example: 1) You code a new route in RegisterRoutes. 2) Compile 3) You request a page, this calls Application_Start 4) There is an exception in your route and RegisterRoutes throws an exception. 5) You attach the debugger. 6) You request the page again to reproduce the error. This is where you notice that the error doesn't happen again, since Application_Start has already been called and attaching the debugger doesn't restart the application. Here are some of the things I know that restarts the application: 1) Edit the web.config...

RegularExpression Routing Class for MVC

I am working with a ASP.NET WebForms website trying to convert it over to ASP.NET MVC 1.0 and need to make sure all the old URLs route correctly. We were using a combination of an HTTPHandler and Custom 404 redirects to give the web site some fancy URLs -- now I need to mimic that functionality with MVC in order not to lose the Google links that the site depends on for revenue. We really only care about the name part of the URI and the hint that it ends in .htm (the .htm extension is mapped to the ASP.NET ISAPI extension handler). So the route I tried to add looked like this: routes.Add( new Route( "{*path}/{name}.htm" , new NameRouteHandler())); However, I got this error message: A catch-all parameter can only appear as the last segment of the route URL. Which was an issue; the path which I tossed away had a lot of optional subdirectories which didn't map well to the MVC Route syntax. What I really wanted was to treat...