Pages

Friday, September 16, 2011

ASP.NET MVC - Upgrading an Existing Preview2 Application to Preview 3

The information in this section describes the changes you must make to modify an ASP.NET MVC application that was created with the Preview 2 release so that it works with the Preview 3 release.

Code Changes

· Update the references to the following assemblies to point to the new Preview 3 versions of the assemblies:
  • · System.Web.Abstractions
  • · System.Web.Routing
  • · System.Web.Mvc
By default, these assemblies are located in the following folder:

%ProgramFiles%\Microsoft ASP.NET\ASP.NET MVC Preview 3

  • For all existing action methods, change the return type from void to ActionResult.
  • Anywhere you call RenderView, change it to a call to return View. You can search for RenderView( and replace it with return View(.
  • Anywhere you call RedirectToAction, prepend the call with the return keyword. Search for RedirectToAction( and replace it with return RedirectToAction(.
  • If you use a strongly typed page, replace <%= ViewData.PropertyName %> with <%= ViewData.Model.PropertyName%>. Rather than replacing the ViewData object with your strongly typed object, the MVC framework now sets the Model property to the instance that you provide.
  • In the Global.asax file, remove the route definition for Default.aspx. In the default Preview 2 template, the route looked like the following example:
routes.Add(new Route("Default.aspx", new MvcRouteHandler())
{
  Defaults = new RouteValueDictionary(new { controller =  "Home", action = "Index", id = "" }),
});
  • In the Global.asax file, find the following default MVC route:
routes.Add(new Route("{controller}/{action}/{id}", new MvcRouteHandler())
{
Defaults = new RouteValueDictionary(new { action = "Index", id = "" }),
});
Replace it with the following route:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
  • Add the following line at the very beginning of the RegisterRoutes method:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  • Edit the Default.aspx file and add the following line:
<% Response.Redirect("~/Home") %>

This redirect is not necessary for IIS 7. This is a workaround for an issue with how the Web server that is built into Visual Studio (the ASP.NET Development Server) works with routing.

Configuration Changes

  • In the Web.config file, you must change the type attribute of the httpHandler entry in the section for UrlRoutingHandler to System.Web.HttpForbiddenHandler. To do this, search for the following string in the file:
path="UrlRouting.axd" type="System.Web.Routing.UrlRoutingHandler, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
Replace it with the following string:
path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
  • Because the version numbers of the System.Web.Abstractions and System.Web.Routing assemblies have been changed to 0.0.0.0, you must update version information in the Web.config file. In the Web.config file, search for the following string:
System.Web.Routing, Version=3.5.0.0
Replace it with the following string:
System.Web.Routing, Version=0.0.0.0
Search for the following string:
System.Web.Abstractions, Version=3.5.0.0
Replace it with the following string:
System.Web.Abstractions, Version=0.0.0.0

http://www.asp.net/mvc

Sunday, July 10, 2011

June 26th Links: ASP.NET, ASP.NET MVC, .NET and NuGet

ASP.NET

  • Introducing new ASP.NET Universal Providers: Great post from Scott Hanselman on the new System.Web.Providers we are working on. This release delivers new ASP.NET Membership, Role Management, Session, Profile providers that work with SQL Server, SQL CE and SQL Azure.

  • SassAndCoffee 0.9 Released: Paul Betts blogs about the latest release of his SassAndCoffee extension (available via NuGet). It enables you to easily use Sass and Coffeescript within your ASP.NET applications (both MVC and Webforms).

ASP.NET MVC

  • ASP.NET MVC Mini-Profiler: The folks at StackOverflow.com (a great site built with ASP.NET MVC) have released a nice (free) profiler they’ve built that enables you to easily profile your ASP.NET MVC 3 sites and tune them for performance.

  • Precompile your MVC Razor Views: Great post from David Ebbo that discusses a new Razor Generator tool that enables you to pre-compile your razor view templates as assemblies – which enables a bunch of cool scenarios.

  • Unit Testing Razor Views: Nice post from David Ebbo that shows how to use his new Razor Generator to enable unit testing of razor view templates with ASP.NET MVC.

  • Bin Deploying ASP.NET MVC 3: Nice post by Phil Haack that covers a cool feature added to VS 2010 SP1 that makes it really easy to \bin deploy ASP.NET MVC and Razor within your application. This enables you to easily deploy the app to servers that don’t have ASP.NET MVC 3 installed.

.NET

  • Table Splitting with EF 4.1 Code First: Great post from Morteza Manavi that discusses how to split up a single database table across multiple EF entity classes. This shows off some of the power behind EF 4.1 and is very useful when working with legacy database schemas.

  • Choosing the Right Collection Class: Nice post from James Michael Hare that talks about the different collection class options available within .NET. A nice overview for people who haven’t looked at all of the support now built into the framework.

NuGet

  • NuGet 1.4 Released: Learn all about the latest release of NuGet – which includes a bunch of cool new capabilities. It takes only seconds to update to it – go for it!

  • NuGet in Depth: Nice presentation from Scott Hanselman all about NuGet and some of the investments we are making to enable a better open source ecosystem within .NET.

Original post can be found here...

Friday, January 29, 2010

Scott Hanselman's ASP.NET Interview Questions

I do a LOT of interviewing here, and for a while we were hiring ASP.NET people.  Here's some of the questions that I asked them.  I came up with these questions because you'd "just know" this stuff if you spent time working on a REAL WORLD ASP.NET site - through design, development, debugging, production debugging, and deployment.

Do they suck? Did I miss any?  How do you think people did?

  • From constructor to destructor (taking into consideration Dispose() and the concept of non-deterministic finalization), what the are events fired as part of the ASP.NET System.Web.UI.Page lifecycle. Why are they important? What interesting things can you do at each?
  • What are ASHX files?  What are HttpHandlers?  Where can they be configured?
  • What is needed to configure a new extension for use in ASP.NET? For example, what if I wanted my system to serve ASPX files with a *.jsp extension?
  • What events fire when binding data to a data grid? What are they good for?
  • Explain how PostBacks work, on both the client-side and server-side. How do I chain my own JavaScript into the client side without losing PostBack functionality?
  • How does ViewState work and why is it either useful or evil?
  • What is the OO relationship between an ASPX page and its CS/VB code behind file in ASP.NET 1.1? in 2.0?
  • What happens from the point an HTTP request is received on a TCP/IP port up until the Page fires the On_Load event?
  • How does IIS communicate at runtime with ASP.NET?  Where is ASP.NET at runtime in IIS5? IIS6?
  • What is an assembly binding redirect? Where are the places an administrator or developer can affect how assembly binding policy is applied?
  • Compare and contrast LoadLibrary(), CoCreateInstance(), CreateObject() and Assembly.Load().

-Scott Hanselman's

Friday, October 23, 2009

C# interview questions and answers

  • What’s the advantage of using System.Text.StringBuilder over System.String? StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.
  •  

  • Can you store multiple data types in System.Array? No.
  •  

  • What’s the difference between the System.Array.CopyTo() and System.Array.Clone()? The first one performs a deep copy of the array, the second one is shallow.
  •  

  • How can you sort the elements of the array in descending order? By calling Sort() and then Reverse() methods.
  •  

  • What’s the .NET datatype that allows the retrieval of data by a unique key? HashTable.
  •  

  • What’s class SortedList underneath? A sorted HashTable.
  •  

  • Will finally block get executed if the exception had not occurred? Yes.
  •  

  • What’s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception? A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.
  •  

  • Can multiple catch blocks be executed? No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.
  •  

  • Why is it a bad idea to throw your own exceptions? Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.
  •  

  • What’s a delegate? A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.
  •  

  • What’s a multicast delegate? It’s a delegate that points to and eventually fires off several methods.
  •  

  • How’s the DLL Hell problem solved in .NET? Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.
  •  

  • What are the ways to deploy an assembly? An MSI installer, a CAB archive, and XCOPY command.
  •  

  • What’s a satellite assembly? When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.
  •  

  • What namespaces are necessary to create a localized application? System.Globalization, System.Resources.
  •  

  • What’s the difference between // comments, /* */ comments and /// comments? Single-line, multi-line and XML documentation comments.
  •  

  • How do you generate documentation from the C# file commented properly with a command-line compiler? Compile it with a /doc switch.
  •  

  • What’s the difference between <c> and <code> XML documentation tag? Single line code example and multiple-line code example.
  •  

  • Is XML case-sensitive? Yes, so <Student> and <student> are different elements.
  •  

  • What debugging tools come with the .NET SDK? CorDBG – command-line debugger, and DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch.
  •  

  • What does the This window show in the debugger? It points to the object that’s pointed to by this reference. Object’s instance data is shown.
  •  

  • What does assert() do? In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.
  •  

  • What’s the difference between the Debug class and Trace class? Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.
  •  

  • Why are there five tracing levels in System.Diagnostics.TraceSwitcher? The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.
  •  

  • Where is the output of TextWriterTraceListener redirected? To the Console or a text file depending on the parameter passed to the constructor.
  •  

  • How do you debug an ASP.NET Web application? Attach the aspnet_wp.exe process to the DbgClr debugger.
  •  

  • What are three test cases you should go through in unit testing? Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).
  •  

  • Can you change the value of a variable while debugging a C# application? Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.
  •  

  • Explain the three services model (three-tier application). Presentation (UI), business (logic and underlying code) and data (from storage or other sources).
  •  

  • What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET? SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it’s a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.
  •  

  • What’s the role of the DataReader class in ADO.NET connections? It returns a read-only dataset from the data source when the command is executed.
  •  

  • What is the wildcard character in SQL? Let’s say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’.
  •  

  • Explain ACID rule of thumb for transactions. Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t), Isolated (no transaction sees the intermediate results of the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after).
  •  

  • What connections does Microsoft SQL Server support? Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).
  •  

  • Which one is trusted and which one is untrusted? Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.
  •  

  • Why would you use untrusted verificaion? Web Services might use it, as well as non-Windows applications.
  •  

  • What does the parameter Initial Catalog define inside Connection String? The database name to connect to.
  •  

  • What’s the data provider name to connect to Access database? Microsoft.Access.
  •  

  • What does Dispose method do with the connection object? Deletes it from the memory.
  •  

  • What is a pre-requisite for connection pooling? Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.
  •  

    Original post can be found here...