Troubleshooting ASP.NET MVC upgrade 1.1 to 2.0

by Michal Rogozinski 25. October 2009 09:13

I couldn’t resist the temptation and decided to upgrade my apps to ASP.NET MVC 2… unfortunately I had ASP.NET MVC 1.1 already installed and they didn’t get along well together. While installing Visual Studio 2010 Beta 2, the MVC 2 part would fail to install.

Having decided that I want to uninstall the older version, I tried to do it. Unfortunately the error message was not very comforting:

Please uninstall the Microsoft Visual Studio Tools component for MVC before uninstalling Microsoft ASP.NET MVC 1.1.

Even though I uninstalled all Visual Studio components, the message would not go away, and I was not able to uninstall ASP.NET MVC 1.1 and thus, I couldn’t install ASP.NET MVC 2.0.

Googling and Binging gave me the idea that on Windows 7 x64, the uninstaller does not delete a specific registry key, which is being checked by the other uninstaller. The key is:

HKLM\SOFTWARE\Microsoft\ASP.NET\MVCTools 1.1

After manually running regedit and deleting the specified key, the ASP. NET MVC 1.1 uninstalls without any problems. Success!

Tags:

Software Development

FTP Active Mode vs. Passive Mode

by Michal Rogozinski 8. August 2009 10:07

FTP is based on Transmission Control Protocol (TCP) and has a connection. It has no connectionless User Datagram Protocol (UDP) component. FTP requires two ports for communication: a command port and a data port. Port 21 is typically the command port at the server; port 20 is the typical data port then using active mode FTP.

Active mode FTP communications is the default mode and starts with the client selection of two ports: n and n+1. The client will use port n to initiate communications to port 21 of the server. When the server responds, the client sends a port command. This command instructs the server which port to use for data communications. It is the server that initiates data communications from port 20 to the client’s data port (n+1). If the client has a firewall installed, the server may be blocked from initiating communications to the client on the data port.

Passive mode FTP communications can be used to correct the problem with active mode communications. Passive mode starts with the client selection of two ports: n and n+1. The client uses port n to initiate communications to port 21 of the server. When the server responds, the client sends a pasv command to the server, the server selects a random port p to use for data communications and sends the port (n+1) to the server’s data port (p).

Notice than when using passive mode, the client initiates communications on the command and data ports. This fixes the problem of the client having a firewall installed that blocks the server’s request to initiate communications on the data port.

Tags:

Software Development

Strongly Typed Views in ASP.NET MVC

by Michal Rogozinski 27. July 2009 17:52

Pretty common scenario when working with Controllers and Views is passing a data entity (or more than one) to it and than rendering the in the view with that data. In this scenario we’re using a common Data Transfer Object paradigm.

There are multiple ways of passing data to views in ASP.NET MVC. One though is of my interest now.

Traditionally you have the View Data Dictionary, which you can stuff with any objects and then read in the view layer. The drawback here is that you have to explicitly cast each member of View Data Dictionary, since the information about type is being lost.

   1: public class HomeController : Controller
   2: {
   3:    public ActionResult Index()
   4:    {
   5:       ViewData["Title"] = "Home Page";
   6:       ViewData["Message"] = "Welcome to ASP.NET MVC!";
   7:  
   8:       return View();
   9:    }
  10: }

A view can be strongly typed, so a developer is able to pass an object to it and define what type of object it is. We can specify the model for the view (or should I rather say DTO) via an overload of the View method in the Controller.

   1: //
   2: // GET: /Note/Create
   3: public ActionResult Create()
   4: {
   5:    return View(new Note());
   6: } 

 

Behind the scenes this sets the value of ViewData.Model property to value passed into the View method. The next step is to change the type of the view inherit from ViewPage<T>. Since there is no code-behind, it’s best to achieve it this way:

   1: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
   2: Inherits="System.Web.Mvc.ViewPage<Note>" %>
Moreover, it’s very common to use enumerable types, in this case we’re getting into:
 
   1: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
   2: Inherits="System.Web.Mvc.ViewPage<IEnumerable<Note>>" %>

The upper will allow us to manage any IEnumerable collection of Note objects, for example List<Note>.

Finally, to use the Model in our view assuming we passed List<Note>:

   1: <ul>
   2: <% foreach (Note n in Model) {%>
   3: <li><%= Html.Encode(p.Title) %></li>
   4: <% } %>
   5: </ul>

Strongly typed views give us the the IntelliSense – less error prone guessing and typos, and so convenient.

Tags: , ,

Software Development

Integrating Multiple Applications

by Michal Rogozinski 29. April 2009 17:47

Having this issue on my mind I’ve decided to go through ways of communicating between apps known in the projects I have been dealing with. I hope it is a valuable source of information for you, as it is a very good sum-up for me.

 

Shared folder / FTP drop-off

The most basic method known to me. Especially good when “communicating” with a really old application or hardware devices that spit out files with data. Two approaches are common in this area – polling every n seconds or registering for directory changes. As for the latter, .NET comes with a very nice FileSystemWatcher class (in System.IO namespace) that can be really helpful when updates are rare but important and you want to avoid scanning the directory every 5 seconds ;)

Here’s a simple example from http://www.dotnetspider.com/forum/147002-FileSystemWatcher-Example.aspx

   1: using System.IO;
   2:  
   3: static void Main(string[] args)
   4: {
   5:     FileSystemWatcher watcher = new FileSystemWatcher();
   6:     watcher.Path = @"C:\";
   7:     
   8:     //Register for events
   9:     watcher.Created += new FileSystemEventHandler(watcher_Changed);
  10:     watcher.Deleted += new FileSystemEventHandler(watcher_Changed);
  11:     
  12:     //Start Watching
  13:     watcher.EnableRaisingEvents = true;
  14:     Console.Read();
  15: }
  16:  
  17: //Event Handler
  18: static void watcher_Changed(object sender, FileSystemEventArgs e)
  19: {
  20:     Console.WriteLine("Directory changed({0}): {1}", e.ChangeType, e.FullPath);
  21: }

 

Sharing a database

Nearly all software environments known to me implement some kind of database interaction. Hence communication between .NET and Java or between old DOS application and an ass-kicking WPF application could be achieved by one connecting into another’s database. Most probably the WPF App would connect into mdb or dbf file of the prior. Really good thing about this kind of communication is that it allows us to implement transactions and locking. It’s never perfect though since we are in the guts of the other domain/model and architecturally we are committing a big faux pas.

There is also a powerful toy that comes with SQL Server 2005 and the successors – Microsoft Integration Services – where you can build data integration solutions (ETL packages). It has quite nice graphical tools for creating and debugging those. It can perform FTP operations, execute SQL statements, send email messages.

Here’s a sample SSIS everyday view. Looks nice and encouraging when you want to stay close to wizards and as far as possible from writing code.

Sample SSIS package view

What happens with SSIS though is that after some time you keep rewriting the same kind of code – pulling data out from a source and storing data in some destination. It gets boring pretty fast…

 

Talking through Web Services

Web Services’ popularity almost exploded after 2005. If you didn’t do SOAP, XML communication you were definitely out of the loop. We’ve quickly learnt how easy it is to asynchronously talk from one application to another. We could send any kind of data, validate it, ACK it and even send errors back! Awesome… but there were drawbacks. Mainly the fact that XML is quite sparse… Serializing data to XML takes time and lots of space. Transferring a XML file over the network had a significant overhead not necessarily in CPU usage but definitely in bandwidth. Serialization and deserialization is quite efficient and not too harsh on the CPU load, however adds an extra layer to the project.

Since we’re dealing with HTTP protocol, when you are in demand of security, you can add one more layer – SSL and have it all nicely wrapped up and safer. For the bigger problem – the bandwidth – implementing compression is quite a relief and noticeable improvement. Again at the cost of the CPU usage.

It’s worth keeping in mind though that Web Services put you in asynchronous mode which brings some extra frustration when dealing with the real world. Especially when debugging and testing. Also when the message format changes, both sides of the communication ought to be updated. Resisting to do so can work at least for a short while. General approach is that both sides should get updated which is inconvenient especially when your interfaces keep growing in time.

 

.NET Remoting

This emerged pretty fast after we’ve realized that web services are cool but too big to operate on. We need our systems to stay robust and to achieve this, we need the requests to be as small in size as possible. There came the .NET Remoting which is not much else than Web Services with binary serialization (instead of XML Serialization).

The speed gain is really helpful here, the drawback? We’re out of commonly used standards so it’s great for internal stuff, and not so great for communicating with other companies.

   1: remoteService T = (remoteService) Activator.GetObject(typeof(remoteService), 
   2:                                  "tcp://host:1500/RemoteService"); 

There is one more thing about .NET Remoting that is sometimes scary. By default it’s not using HTTP, it’s a straightforward TCP. Which means that if you are using Squid or any other Proxy, your requests will not get through. Fortunately it is possible to run a .NET Remoting service with HTTP protocol just by registering an HttpChannel in place of a TcpChannel. This really helps with stubborn local administrators who think that opening another port in the firewall is a disaster.

There is lots of examples available online, I’m usually getting back to this one when looking for code snippets: http://www.codeproject.com/KB/IP/remotingchatsample.aspx

 

MSMQ Messaging

MSMQ, which has been there since 1997, is the first professional approach to communication I’ve ever experienced when dealing with communication. And this includes JMS as well. What we get here is a durable and guaranteed delivery over multiple protocols with such advanced features as triggers, multicasting and authorizations. MSMQ is a service provided by operating system, not a language feature. To be fair with J2EE, JMS is an Application Server’s service. What is important is that the messages are handled  outside of Application Domain in a different process. MSMQ handles durable messaging and reliable delivery. The technology involved is astonishing.

With Messaging we’re finally in asynchronous mode. We can implement pooling and prevent killing our applications with initial loads or unpredicted volume of traffic. I’m convinced that all external interfaces to our systems should be using a queuing interface unless we are convinced that there is a controlled amount of traffic.

There is one thing worth mentioning. MSMQ has multiple modes of operation: private queue and public queue. Private queues are accessible directly from the code whereas public queues are available through Active Directory which sounds at least troublesome and performance-problem-some. Thus it’s recommended to use private whenever possible.

 

Windows Communication Framework

It should not take too long to notice the Net.MSMQ transport in WCF, which means that it is strongly based on the old friend - MSMQ. Which is a great news because it is a neat and stable solution. That’s pretty much it for good oldies. What’s new and unfortunately painful is all the configuration hell. One can die in the bushes of XML settings and configurations. I really hope that they will come up with a GUI for that, and as soon as in VS 2010! We’ll see. For now I see more pain than gain and I’m waiting for some improvements.

 

Other solutions : ActiveMQ, TipCo, BizTalk, MassTransit

Everything depends on your needs, how much you want to spend, whether you need support or what kind of applications you want to communicate with each other.

MassTransit is something much more that just a MSMQ … it is a really interesting project with which I haven’t dealt yet, but I would love to try it one day. It is definitely a next step in the queuing world.

Tags: , , , , , ,

Software Development

New IIS7 Rewrite Module and Canonical URLs

by Michal Rogozinski 22. April 2009 17:49

Trying to make my blog more SEO’ed, I’ve gotten to the point of canonical URL addresses. If you want to be search engine friendly, there has to be one address you are available at, and all other aliases should redirect to it rather than serve the same content.

Trying to achieve it from scratch would be pain, especially when I already had nice and pretty rules in my .htaccess files. And to my astonishment, there is a nice way of importing mod_rewrite rules into IIS7 URL Rewrite rules! Unbelievable but true.

First, though, you might actually be lacking the URL Rewrite plug-in. you can download it from IIS website: Download the x86 version for IIS 7.0 or Download the x64 version for IIS 7.0 .

Next after you have successfully installed the plug-in, you’ll easily see a way to import your own mod_rewrite rules, here’s what I came up with:

   1: <rewrite>
   2:   <rules>
   3:     <rule name="Canonicalization Rule" stopProcessing="true">
   4:       <match url="^(.*)" ignoreCase="false" />
   5:       <conditions>
   6:         <add input="{HTTP_HOST}" pattern="^www\.michalrogozinski\.com" negate="true" />
   7:         <add input="{HTTP_HOST}" pattern="^$" ignoreCase="false" negate="true" />
   8:       </conditions>
   9:       <action type="Redirect" redirectType="Found" url="http://www.michalrogozinski.com/{R:1}" />
  10:     </rule>
  11:   </rules>
  12: </rewrite>

What I didn’t like about the google’s answers was that you had to name each of the possible URLs your website is accessible at, while with the above rule, you don’t have to worry if it’s a localhost, IP address, or 10.000 different domain names that you bought so nobody steals your identity.

Tags: , , ,

Software Development

Microsoft Surface

by Michal Rogozinski 22. April 2009 11:25

Microsoft Surface

During a lunch break at Devscovery 2009 conference in New York, I had a chance to check out some cool stuff from Microsoft - Surface. It's like a big, coffee table size iPhone. At least at first, but I've quickly learned that there's more more to it - size does make a huge difference. Even though this one's resolution was only 1024x768, it brought me so many ideas on where and what could be done fancier with it to make users scream "THAT IS AWESOME", when using apps I work on.

Here on the video there is a simple map application from Virtual Earth, but it gives an idea of how different the whole experience gets when you start using Surface. Not only do you forget about keyboard and mouse, but also after it just feels awkward using them again - almost like getting back to Morse code communication (my dad's comparison).

Surface implements WPF to the full extent - and even goes beyond, since there is nothing like up or down, straight or crooked, everything depends where you stand.

Michal playing with Virtual Earth on Microsoft Surface

Apparently BMW is using it already as well as some entertainment industry in Las Vegas. Pretty neat stuff!

 

Kubek and Bethany playing with Mirosoft Surface

 

And one more video :

Tags: , ,

Software Development

Michal Rogozinski

Michal Rogozinski

 

 

Contact me via email  E-mail    My status  Skype me

My ScheduleFree/Busy schedule

 

Profile for microg