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

ActionResult Helper Methods in ASP.NET MVC

by Michal Rogozinski 27. July 2009 16:24

Just wanted to quickly summarize default ActionResult methods in ASP.NET MVC Framework. I’m looking for them so often that I just need them all to be in one place.

Redirect(…) Returns a RedirectResult, which redirects the user to the appropriate URL;
RedirectToAction(…) Returns a RedirectToRouteResult, which redirects the user to an action using the supplied route values;
RedirectToRoute(…) Returns a RedirectToRouteResult, which redirects the user to the URL that matches the specified route values;
View(…) Returns a ViewResult, which renders the View to the response;
PartialView(…) Returns a PartialViewResult, which writes the specified content (string) to the response;
Content(…) Returns a ContentResult, which writes the specified content (string) to the response;
File(…) Returns a class that derives from FileResult, which writes binary content to the response;
Json(…) Returns a ContentResult containing the output from serializing an object to JSON;
JavaScript(…) Returns a JavaScriptResult containing JavaScript code that will be immediately executed when returned to the client;

Returning ActionResult object has its advantages over returning simple types or tampering with the Response object. First of all it makes your intentions slightly more clear. It is also easier to unit test.

Also bear in mind that there are implicit conversions when returning a non-ActionResult types:

  • Action invoker replaces null results with an instance of EmptyResult. This follows the Null Object Pattern.
  • Action invoker treats void the same way as if it returned null, and thus an EmptyResult is returned.
  • For Object (anything other than ActionResult) the action invoker call ToString using InvariantCulture on the object and wraps the resulting string in a ContentResult instance.

Tags:

The Big Apple

by Michal Rogozinski 4. May 2009 18:23

Brooklyn Bridge

US Population is kind of unevenly spread across the continent and there are two opposite corners that are extremely densely populated – Los Angeles area and New York. I think it’s because of this density that NYC has it’s own energy and lives its own life. It’s funny and unexplainable, but everyone who has been there says that its a totally different city. Why so? The history? The population? The language dialect? Amazing, tempting and strangely familiar if you’ve been watching some popular TV series such as Gossip Girl.

Ok, so the rules of thumb start from NOT USING a car. If you are used to regular driving, and other people letting you in just after you’ve turned on your signal, you’ll get seriously surprised … and frustrated sooner than you think. One more thing … don’t take your hand from your horn… New Yorkers simply love to honk, almost like it was “Hi, how are you” , and don’t be offended, most of the times it should translate to: “Hi, I’m close, don’t be surprised”. Funny, but I can see that as a consequence of the city growing out of the proportion and Manhattan Island staying still the same size.

Brooklyn BridgeSome facts to make you realize how big of a city we’re talking about: City’s population is over 8 million folks. Which gives it a density of 10500 people per square km. This is a lot! The Metropolis is about 18 million people which is a half of entire Canadian population.

 

Why come to New York?

Well it’s a rhetorical question… Depending on what your desires are, you can spend all amounts of time and money shopping, entertaining, eating, sightseeing 24 hours a day. There are numerous and enormous books and guides you can buy all over the world about NYC, so I’m just going to focus on what I find very attractive about the city and whenever I’m visiting the Big Apple, I gladly come back to those places.

 

  1. Empire State Building – going up over 80 floors or over 100 for an extra $15 is an electrifying experience especially by night. Take a good SLR camera with a tripod and be prepared for breathtaking experience! If it’s cold outside or raining it can literally be breathtaking ;) I’m still coughing after that night but I don’t regret. So be warned :)Statue of Liberty
  2. Statue of Liberty – there are multiple options to see Ms Liberty – all of the water based ones start at  Battery Park at the southern end of the Manhattan Island. If you don’t like getting stuck on the island for long, the best is to take a free Staten Island ferry that goes just by Liberty Island. You can make it in 45 minutes there and back if not less than that.
  3. Rockefeller Center is where you can buy gifts, have fancy coffee and take a picture at one of the most popular fountains in the world. There is also Radio City – one of the most famous music halls.
  4. Times Square– an intersection you’ll never forget – when you see it, especially after dusk. Seems to be the brightest spot on Manhattan with all the electronic billboards, neon lights and flowing rivers of people speaking all possible languages. It’s a perfect place to go to after a whole day, just to hang out, maybe have a beer, buy some cheesy souvenirs.
  5. South Street Seaport is where you go for a beer, food and some street performances. It’s a reconstructed historic maritime district, with its cobbled streets. It’s close to Ground Zero and New York Stock Exchange on Wall Street, which both are worth seeing.
  6. Broadway Musicals – not everyone is a fan of those, but all of us heard of them. So why not treat yourself and see Grease or some other performance in their original location? Musicals are a great part of American culture and New York City is definitely in the centre of this term along with London in Great Britain.
  7. Central Park – an amazing and spectacular thing – an enormous chunk of land simply cut out of the skyscrapers area and turned into a park. Very popular one and present almost in every movie about New York. Definitely worth going to when you feel like taking a break from the loud city noises. Empire State Building

Getting in and out

Ok, so you want to get to New York… there are 3 big airports : JFK, LaGuardia (LGA) and Newark (EWR). On top of those there are minor airports as well as well as other cities. Sometimes it is a lot cheaper to fly to a distant airport and rent out a car one way to the city rather than flying to the most popular airports, especially when there are more travellers involved.

Some travelers take advantage of low-cost carriers that serve Long Island MacArthur Airport in Islip, New York, and Westchester County Airport in White Plains, New York. Increased growth is also expected at Stewart International Airport in Newburgh, New York.

The traffic can be a killer in that city so don’t trust your GPS timing unless you’re using train or subway. Getting to and from an airport can take you longer than you expected so leave early and have an extra coffee at the airport after your security check :) Unless you like a lot of adrenaline in your blood :)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Accommodation

You’ll quickly find out that NYC is not a cheap place to sleep at unless you’re staying 2 hours subway ride from downtown – which you don’t really want to do. So just be prepared for spending some more for your hotel and believe me, after walking most of the day, you will need a good night sleep in a comfy bad :) It’s a good idea to book a hotel in advance, especially when you’re arriving from abroad … in fact it’s a Homeland Security’s requirement.

Visit the photo gallery of my trips to New York.

Tags: , ,

Voyages

Spring in Washington DC

by Michal Rogozinski 30. April 2009 13:20

This was really great time in DC. So close to New York and so different. It was my second visit to the nation’s capital, although the first one I had time to ramble around the city. Of course not as much as I’d love to,MR and Washington Monument but still better than nothing.

First thing that surprised me was how green and spacious the city is. At least the tourist destination part of it. It has very spacious parks and squares stuffed with most popular buildings, statues and monuments in the world. Here’s what I recommend when you are on a business trip passing by and want to get a sip of DC.

The very first thing you will notice, no matter how and when you come to the city is Washington Monument – a large sand-colored obelisk which was constructed to commemorate the first U.S. president – George Washington. That’s as far as I’m going to get into the history since it’s not the most important thing about the obelisk. Michal at U.S. CapitolThe biggest advantage is that it is a great navigation point around the town. Keep that in mind when wandering around.

From the obelisk, it’s a nice and easy walk down to The U.S. Capitol Building - Washington, DC's Meeting Chambers for the Senate & the House of Representatives. Since everything around – the parks, buildings streets is big, I would even say enormous, it takes quite a walk, but with spring weather, there is nothing more pleasant than such walk. I didn’t go in but it is possible to see the U.S. Capitol inside as a guided tour and by yourself. Here’s detailed info on that: http://www.visitthecapitol.gov/ 

From there, it’s a nice walk up Pennsylvania Avenue, just by MR in front of The White HouseFBI Headquartersand some other quite important institutions straight to The White House – home for every U.S. president except for George Washington. A good source of information for folks interested in visiting The White House is here: http://www.whitehouse.gov/about/tours_and_events/ Make sure you prearrange your visit since there are quite strict security measures involved and you might not be able to go visit everywhere you wanted without a prior registration.

A couple of words on getting in, out and about as it came to me as a surprise that the DCA airport is situated literally 10 minutes from the Washington Monument. It is really very convenient! Similarly as for other bigger cities, I would recommend using public transit and most of all your own feet, even though there’s miles before you to walk in that city. Is there any other better way of getting to know the city’s atmosphere? Leave your car by the Washington Monument, start walking, talk to people, they are really friendly, ask other tourist what they’ve seen, how they got somewhere!

If you’re planning on staying in the town for longer, there is a pass you can obtain to save you some money and time: The Washington DC Power Pass .

See my facebook photo gallery from this trip

Here’s some other attractions worth mentioning:

  1. Washington DC is packed with monuments and memorials, and they are very impressing to the full extent of this word. Americans are very patriotic and on the contrary to what many Europeans say they do have a lot of history events to . Memorials: African American Civil War Memorial and Museum, Arlington National Cemetery, DC War Memorial, Franklin Delano Roosevelt Memorial, George Mason Memorial, Jefferson Memorial, Korean War Veterans Memorial, Lincoln Memorial, Pentagon Memorial
  2. Visit Georgetown – historic waterfront district
  3. Attend a show at The Kennedy Center
  4. Visit The National Archives building where you can see such documents as the Charters of Freedom: the Declaration of Independence, United States Constitution and the Bill of Rights and lots of others.

A bit crazy and amateur video from this trip:

Spring in Washington DC

Tags: , ,

Voyages

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

Thoughts on New Year's Eve

by Michal Rogozinski 27. December 2008 22:29

Just wanted to share a recipe for having New Year's Eve more than once. I got inspired during Christmas brunch when I met Katya who's originally from Australia.

For the New Year's Eve one should first go to the archipelago of the Kingdom of Tonga and drink the champagne over there than, when the party is over, catch a plane to Samoa Islands which would "send" them to the morning of the day before and still would have the whole day ahead. As soon as the Earth revolves the full 360 degrees (24 hours later) we get a chance to celebrate New Year's Eve again.

Map picture

I know it's weird, but I think this is as far as we can get when talking about traveling in time in real life :).

Tags: , ,

Voyages

Michal Rogozinski

Michal Rogozinski

 

 

Contact me via email  E-mail    My status  Skype me

My ScheduleFree/Busy schedule

 

Profile for microg