# Wednesday, 05 March 2014

This handy pdf document will show an overview of the lifecycle of an ASP.NET MVC 5 application. Created by Cephas Lin (Microsoft).

Grz, Kris.

Wednesday, 05 March 2014 07:49:54 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, 04 March 2014

On a regular basis Microsoft brings out cool and easy to follow tutorials. I just noticed that the ones about Entity Framework and ASP.NET MVC got updated.

For Entity Framework the following new things in version 6 are handled:

  • Connection resiliency
  • Command interception
  • Code-based configuration
  • Async
  • Stored procedures

9 tutorials were refurbished:

And 3 new tutorials were created:

For people who’re still on older versions don’t despair, they’re still available under http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4

Grz, Kris.

Tuesday, 04 March 2014 12:08:00 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, 20 January 2014

Recently we upgraded to Visual Studio 2013 at my client. This morning my colleague came over and had a small problem. Some of the .svc services gave 404 errors. As I had another solution open of which I knew the in project .svc services simply worked I sat down with him. Some searching on the internet, trying out http activation, reregistering WCF, … it didn’t work out.

The difference between both solutions was that the one I was looking at was Webforms while the other one was MVC4 based. Aha! I used Nuget to include routedebugger. A super handy package for, well, debugging MVC routes. However since the .svc files themselves were put into a /Services subfolder I had to make it up like this:

routes.IgnoreRoute("Services/{resource}.svc/{*pathInfo}");

Put this at pretty much of the top of all the route configuration so that it gets picked up early.

The funny part was that the .svc was working pretty fine, even the wsdl could get obtained. However when we wanted to make a REST call to a specific method it gave 404 mistakes. Turned out to be that the default {controller}/{action}/{id} that ships with every template caught it. Making a more specific rule near the top of the configuration dealt with it and it all started out working smoothly again.

After testing it locally with IIS Express we also tested it out on Cassini due to the fact that the servers are still not up to IIS 8 at the moment and that also worked out fine.

Grz, Kris.  

ASP.NET MVC | MVC | WCF
Monday, 20 January 2014 18:52:16 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, 16 September 2013

You want to know more about ASP.NET MVC (4) and Web API? Well tomorrow you can do just that. Simply join the Microsoft Virtual Academy broadcast and enjoy the ride of these awesome technologies.

This will be covered during the course:

  • Overview of MVC
    • What is MVC?
    • How is MVC different from Web Forms?
    • Why use MVC?
  • Developing ASP.NET MVC 4 Controllers and Models
    • Creating Controllers
    • Adding Actions
    • Creating MVC Models
    • Working with Code First
  • Developing ASP.NET MVC 4 Views
    • Razor Syntax
    • HTML Helpers
    • Partial Views
  • Integrating JavaScript and MVC
    • Using AJAX
    • Using jQuery
  • Implementing Web APIs
    • Developing Web API Controllers
    • Calling HTTP Services from Client-Side Code
  • Deploying ASP.NET MVC Site Walkthrough
    • Creating a site on Windows Azure Web Sites
    • Deploying an ASP.NET MVC Application with Visual Studio Web Deploy
  • What’s Next and Resources
    • Sneak peak at Visual Studio 2013 (Preview) and ASP.NET MVC 5 tooling
    • A look at real-time communications with SignalR
    • Resources for keeping up with new ASP.NET releases

Simply register here: http://www.microsoftvirtualacademy.com/liveevents/developing-asp-net-mvc4-web-applications-jump-start#fbid=r4qO—FJ7Ye.

For more information about these technologies also be sure to read about them here:

Grz, Kris.

Monday, 16 September 2013 08:13:55 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, 04 April 2013
# Sunday, 08 January 2012

If you provide a way for your user to make an appointment it’s always a good idea to provide a reminder mechanism for him or her. A nice way to do this is to send a mail. But a mail alone is sometimes not enough and Microsoft Outlook users for example would rather love to see a .ics appointment attached.

The System.Net.Mail namespace provides the needed functionality to get this recipe cooking in no time and will taste great afterwards.

First part of the recipe are the helper classes which hold the functionality for making up the ics content and sending a mail depending on provided input.

The Mailing class:

using System.Net.Mail;
using System.Web.Configuration;

namespace IcsAsMailAttachment.Controllers
{
    public class Mailing
    {
        public void SendMail(string from, string to, string subject, string body, Attachment attachment)
        {
            using (MailMessage mailClient = new MailMessage(from, to, subject, body))
            {
                mailClient.Attachments.Add(attachment);
                mailClient.IsBodyHtml = true;

                SmtpClient smtp = new SmtpClient(WebConfigurationManager.AppSettings["mailserver"]);

                smtp.Send(mailClient);
            }
        }
    }
}

This class does the actual sending. The mailserver, on line 15, is retrieved from the web.config file appSettings section. This makes it easy for the site admin to change the mail server without having to adjust and redeploy the code (saving time and money).

The Appointment class:

using System;
using System.Text;

namespace IcsAsMailAttachment.Controllers
{
    public class Appointment
    {
        private string GetFormatedDate(DateTime date)
        {
             return string.Format("{0:00}{1:00}{2:00}", date.Year, date.Month, date.Day);
        }

        private string GetFormattedTime(DateTime dateTime)
        {
            return string.Format("T{0:00}{1:00}{2:00}", dateTime.Hour, dateTime.Minute, dateTime.Second);
        }

        public string CreateIcs(string subject, string location, DateTime startDate, DateTime endDate)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("BEGIN:VCALENDAR");
            sb.AppendLine("VERSION:2.0");
            sb.AppendLine("PRODID:-//hacksw/handcal//NONSGML v1.0//EN");
            sb.AppendLine("BEGIN:VEVENT");

            string startDay = string.Format("VALUE=DATE:{0}{1}",
                GetFormatedDate(startDate), GetFormattedTime(startDate));

            string endDay = string.Format("VALUE=DATE:{0}{1}", 
                GetFormatedDate(endDate), GetFormattedTime(endDate));

            sb.AppendLine("DTSTART;" + startDay);
            sb.AppendLine("DTEND;" + endDay);
            sb.AppendLine("SUMMARY:" + subject);
            sb.AppendLine("LOCATION:" + location);
            sb.AppendLine("END:VEVENT");
            sb.AppendLine("END:VCALENDAR");

            return sb.ToString();
        }
    }
}

The Appointment class does the heavy lifting of generating the string needed for the ics markup. Two helper methods are put in place to get a nicely formatted Date and Time string.

The SendMailController class:

using System;
using System.IO;
using System.Net.Mail;
using System.Text;
using System.Web.Mvc;

namespace IcsAsMailAttachment.Controllers
{
    public class SendMailController : Controller
    {
        //
        // GET: /SendMail/

        public ActionResult Index()
        {
            string ics = new Appointment().CreateIcs("A great meeting to attend!", "In the cloud",
                new DateTime(2012, 2, 3, 18, 0, 0), new DateTime(2012, 2, 3, 22, 15, 0));

            MemoryStream ms = new MemoryStream();
            UTF8Encoding enc = new UTF8Encoding();
            byte[] arrBytData = enc.GetBytes(ics);
            ms.Write(arrBytData, 0, arrBytData.Length);
            ms.Position = 0;

            // Be sure to give the name a .ics extension here, otherwise it will not work.
            Attachment attachment = new Attachment(ms, "Appointment.ics");

            new Mailing().SendMail("from@contoso.com", "to@ymca.com", 
                "The subject", "<strong>Welcome to the cloud!</strong>", attachment);

            return View();
        }
    }
}

The SendMailController class, I tested this in an ASP.NET MVC 3 web application, creates a new ICS appointment on line 16. For being able to send the attachment without first having to save it to disk we create a MemoryStream instance on line 19 and transform our ics to a byte array so that we can pass it along in the constructor of the Attachment class on line 26. The highlight is on line 26 as you will need to provide the .ics extension in the name there.

When testing this you might want to send it directly via a mail server. However this might get the sys admin at your company upset or perhaps gets the sender email address that you use blacklisted. For this purpose you can tell ASP.NET to drop the generated mail on disk instead. Just be sure to turn that off when you are deploying to a live production as otherwise nobody will receive your emails!

Email settings in web.config:

<?xml version="1.0"?>

<configuration>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="C:\temp\mails" />
      </smtp>
    </mailSettings>
  </system.net>

 

The results:

Once the mail has been sent, it will appear in the designated pickup directory location as specified in the web.config.

Pickup folder for ASP.NET mails

Double clicking on the .eml file opens it up in in the associated application, for me that is Outlook.

The email that was sent

There you see the Appointment.ics file. Remember the name we gave on line 26 in the SendMailController? Yes, that is exactly the name, and correct extension, that was provided. Double click the ics file and you can see the appointment.

The ICS file opened ready for adding it to the agenda in Outlook

The date and times come from the parameters passed in the SendMailController class on line 16 and 17.

As you can see, it is quite easy to set this up with just a bit of code. Providing the opportunity to add an appointment directly to the agenda of the interested user is a great benefit. They don’t have to create one themselves, enter in the dates and hours, possibly making mistakes when doing so, … Make it easy for your customers to keep their agenda up to date in a quick and easy way and they’ll love it.

Grz, Kris.

Sunday, 08 January 2012 14:51:10 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [1]  | 
# Tuesday, 27 July 2010

Today Microsoft released a new version of their MVC project. Still in preview but it looks promising, especially because the new view engine Razor got in it. Razor you say? That sounds familiar. And it should because it’s also a part which shipped with the WebMatrix stack. This’ll make it easier for people starting with WebMatrix to get on track with MVC 3 as well.

Be sure to read the following articles/announcements:

If you want the goods then download it here.

Grz, Kris.

Tuesday, 27 July 2010 19:30:21 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, 04 May 2010
Being a pimp with Silverlight (using ASP.NET MVC2 and jQuery) was my first presentation for the Belgian user group Visug.
Tuesday, 04 May 2010 10:21:32 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [1]  | 
# Friday, 31 July 2009

Great news for the ASP.NET MVC fans. After a release of MVC 1 earlier this year today the first preview of version 2 has been placed on the download servers.

Here are the announcements of Scott Guthrie and Phil Haack.

Grz, Kris.

Friday, 31 July 2009 09:21:35 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, 31 March 2009

Just found on twitter about the release of the ASP.NET MVC Training kit.

Grz, Kris.

Tuesday, 31 March 2009 08:35:32 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, 24 March 2009

I was browsing on the new pages for ASP.NET MVC on www.asp.net and noticed that besides Storefront and Nerddinner there was another tutorial guide available: Contact manager by Stephen Walther. It has currently already 7 tutorials:

Some more reading for me the next days…

Grz, Kris.

Tuesday, 24 March 2009 21:53:39 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, 18 March 2009

Noticed it a couple of hours ago on the forums that someone was able to download the bits and just noticed that the download link itself was available: http://www.microsoft.com/downloads/details.aspx?FamilyID=53289097-73ce-43bf-b6a6-35e00103cb4b&displaylang=en.

ASP.NET MVC 1.0 provides a new Model-View-Controller (MVC) framework on top of the existing ASP.NET 3.5 runtime. This means that developers can take advantage of the MVC design patterns to create their Web Applications which includes the ability to achieve and maintain a clear separation of concerns (the UI or view from the business and application logic and backend data), as well as facilitate test driven development (TDD). The ASP.NET MVC framework defines a specific pattern to the Web Application folder structure and provides a controller base-class to handle and process requests for “actions”. Developers can take advantage of the specific Visual Studio 2008 MVC templates within this release to create their Web applications, which includes the ability to select a specific Unit Test structure to accompany their Web Application development.
The MVC framework is fully extensible at all points, allowing developers to create sophisticated structures that meet their needs, including for example Dependency Injection (DI) techniques, new view rendering engines or specialized controllers.
As the ASP.NET MVC framework is built on ASP.NET 3.5, developers can take advantage of many existing ASP.NET 3.5 features, such as localization, authorization, Profile etc.n

Time to read the free eBook from Scottgu: http://weblogs.asp.net/scottgu/archive/2009/03/10/free-asp-net-mvc-ebook-tutorial.aspx.

Grz, Kris.

Wednesday, 18 March 2009 12:02:18 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, 27 January 2009

Just read the news on Scott Guthrie's blog that ASP.NET MVC RC got released today. That’s good news as this means that the final version will probably ship soon as well. Being a fan of jQuery since a couple of months, and already using it in production code, it’s great to see that it MVC ships with this great javascript library as well. Today still with version 1.2.6 but the 1.0 final release of MVC will have 1.3.1 included which is way more performing when you take a look at the graphs.

Grz, Kris.

Tuesday, 27 January 2009 23:45:44 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |