Blog Views


Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts

Sunday, October 23, 2011

MVC – The dreaded "Multiple types were found that match the controller named"

So I have spent time on a project involving MVC and have this dreaded issue that many users seem to have with the routing once you change any of the defaults (for instance areas and namespaces). The error is "Multiple types were found that match the controller named"

After a lot of banging my head against the wall, crying and almost throwing my laptop out the window, i came across a web site by John Plummer which mentioned that VS likes to keep your origional executable
from when you first created the project and instead of renaming the exexecutable, it just creates another one. This is one of the usual major issues that this error can created.

Another issue that can cause this is the changing of namespaces and adding areas. If you add the new string to the end of your area registration page like below, it will route your area's to the correct controllers:

new { action = "Index", id = UrlParameter.Optional }, new string[] { "CISE.UserInterface.Controllers"}

Hope this helps others!!

Monday, October 17, 2011

MVC User.Identity.Name failure

So I wanted to make a quick post regarding MVC with new applications (Internet or empty) that got me a few times now, so I can only imagine how many others this has nailed.

Apparently there is a "Known issue" where some MVC applications are not able to get the User.Identity populated with just <authentication ="Windows"/>. The known issue was found under Known MVC issues
In some cases you are also required to add the following line to the <appSettings> section of the web.config:

< add key="autoFormsAuthentication" value="false" />

I hope this helps some folks in their MVC journey!

Reference:
Dan Lewis' Development and Technology Blog

Friday, October 14, 2011

Azure.. Love it or hate it's here

So what is Azure??

This post I thought I'd share what Azure is and what it is good for. Azure has become a new Windows buzz word that is all over the internet with little explanation, so here it goes.

Azure is Microsoft's attempt at taking hardware from the Data center and placing it into the cloud. So what does this mean? This means that the Software Engineer and IT team no longer have to worry about things like SQL server and Windows server set up. This is all done within the cloud. Obviously there are pros and like there is with everything else. It's kind of like when host providers started to host websites. Same thing. The process of building the web server ( memory, hard drive space and such), as well as getting upload bandwidth speeds to handle the amount of traffic you hope to get is placed in the hands of the hosting provider. Providers such as go daddy or network solutions. Azure takes the same hosting concepts and applies them to software / database development. An excellent place to start to discover the benefits to this new Microsoft platform is this website: Learn about Azure


Who is this good for and why?


Azure is good for a wide range of people for a variety of reasons. Even if you are a bigger company, you still can utilize the power of Azure with the power of lack of knowledge so to speak. You software development team can spend less time worrying about the set up of SQL or setting up Windows server and more time on the project at hand. On the downside this also gives the company less control and thus can cause issues where there are complicated scenarios with things like permissions and such.
A lot of this in the end will depend on how well Microsoft support is and how the handle companies needs. I'm sure it will no doubt be support based on a big fat monetary scale.

Tuesday, October 11, 2011

ASP.NET versus MVC Compare the Big Web Guns

Introduction


So I have seen a lot of ASP.NET Web Forms versus MVC blogs out there and I thought I'd put my two sense in as well. I used to be a big PHP and MySQL programmer, mainly out of lack of funds in other jobs and I have to say, when I first went to Web Forms, it was interesting to say the least. I can understand that the Web Forms concept came out of a need to allow Windows Forms programmers the ability to quickly adapt themselves into web world. Unfortunately, this came at many prices such as speed and browser compatibility. This post will try to explain both from a theoretical and practical side instead of learning each.

ASP.NET Web Forms


What is this Web Forms and where did it come from?

Web Forms has been around since January 2001 and was a replacement for ASP Classic by Microsoft programmers who needed a way to design web sites without much HTML or JavaScript knowledge. This new approach also allowed any back-end code (also know as code behind) to be written in .NET C# or VB. This and the dragging and dropping of controls helped in the transition from application to web platforms. Although a nice thought, there have been quite a few major pitfalls that have caused ASP.NET to be hard to work with.

Microsoft go wrong?? Never!!

ASP.NET has had some hard times through the years, but even now have some major issues that have kept it on the back burner when it comes to very serious Web Developers who need cross browser compatibility and fast performance. Where this comes out the most is when trying to do things such as pull client side code into the aspx file or styling your code. Master files were created to make template files that all other web application files within a project can use. Using Master files cause odd ID tags for controls to populate into the scrambled characters such as ct10034343. This makes it very difficult in JavaScript to access the DOM for things such as validation and CSS styling. Now you might be thinking, well just do the validation in the code behind. This will work, but it will cause performance lag. Depending on the calculation required to validate the form, there may be major lag times!

The other major thing that was introduced with ASP.NET is stateful applications inside a stateless protocol (HTTP). What does this all mean? It means that ASP.NET has the ability via ViewState to keep the state of the various .NET Controls as well as states of various strings and objects you may need to retain (such as paging or sorting). Although again a great idea, the ViewState has been used improperly by the majority of the developers whom use it. Most developers use that to store massive amounts of data or objects and this is sent to the Client EACH REFRESH! As you can obviously tell, this can bring performance down in a hurry...

What does this mean? No more Web Forms?

In my opinion. No. I think Web Forms is here to stay for a bit if not indefinite. This is for several reasons. One of those reasons is that it is still a fantastic tool for RAD applications (Rapid Application Development). When you need a simple form or newsletter tool, Web Forms is still great. This is true especially for the application programmer unfamiliar with web technologies such as HTML, CSS and the XHTML a stricter version of HTML.

Another reason is that Web Forms have been around for a long time and not everyone will just one day say "Lets migrate to MVC, screw Web Forms!". This will not happen for many reasons, some of which are resources and knowledge-base. For the application programmers who wrote the Web Forms, there will be a larger learning curve that will have to be addressed.


ASP.NET MVC


What is an MVC??

MVC (aka Model-View-Control) is a design model / architecture that was originally developed in the late 70's to create a separation of concerns. In it's simplest form, this means that all the different aspects of an application (Meaning Data Access layer - Calling Code - UI) are logically separated into different folders and classes according to the MVC architecture. The architecture has since been migrated into the .NET Framework and labeled ASP.NET MVC. It's ideas have taken the web world by storm as it is very hard to implement this architecture ( if even possible, I have never tried myself) in the Web Form model. MVC also allows for excellent Unit testing. i will not go into detail here, but thought it should be mentioned.

MVC is also a stateless as apposed to stateful like Web Forms. Stateless means that each time you refresh the page or POST (not POSTBACK), you loose the state of the page and anything that relates to it. There are things to help with this like ViewData which unlike ViewState lives on the server, not the client computer.

Model aka Data Access Layer aka prince (just kidding)

In this case the DAL is the Model (somewhat.. I'll explain better in other posts where we are discussing more technical aspects of MVC ). The Model is used to handle interfaces and repositories that hold all the "code behind" and data calls whether it be database, lists, server files etc. This separates data access layer logic and business logic ( validation for example) from UI logic via the controller.


View (User Interface or HTML)

Through the View MVC displays W3C compliant (assuming you code it that way) HTML formatted code. This makes it much more browser compliant (even IPad and IPhone). There is no hidden HTML characters in the ID's or extra gibberish that only IE understands. MVC also does a lot of object binding between the View, Model Controller making it very easy to use strongly data typed objects throughout your code. This allows you to easily utilize Visual Studio's awesome Intellisense.


Controllers (The BabbleFish)

The Calling Code or the translator (babble fish if you like Douglas Adams :) ) is known as the Controller. This handles the requests between the view and the model. This allows you to "almost" completely remove any Business or Data logic from the View logic. This allows you to not only focus on one section at a time, but also guarantee what your HTML and styles will output like and in turn better browser compatibility.


So what does it all mean?

So whats this all mean? Is MVC the god among men of web development? Will Web Forms fizzle out and never grace our presence ever again? Not likely. As i mentioned above, Web Forms are still widely used and is still an excellent RAD development web application framework. It is also a great alternative for windows application programmers who know nothing about web development and don't really wish to know the specifics in detail.

If on the other hand, you are looking to have a fast growing enriched site with web applications that provides clear HTML standard output, better performance / faster load times and separation of concerns, you may want to take a closer look at MVC. Its core is still .NET, so a lot of the code is the same which is great, but there are some newer syntax in the MVC 2 and 3 releases that you will need to learn and understand, but if you develop in .NET currently it should be too bad. The bigger learning curve to overcome will be understanding how things like POST and Refreshing works.

I hope this has been informative and you view my other posts.