Wednesday, 18 March 2015

Day 2- Installing ASP.NET MVC 4

Software Requirements for ASP.NET MVC 4
ASP.NET MVC 4 runs on the following operating systems:
• Windows XP Service Pack 3, Windows Vista Service Pack 2, Windows 7, and Windows 8
• Windows Server 2003 Service Pack 2, Windows Server 2003 R2 (32-bit x86), Windows
Server 2003 R2 x64 editions, Windows Server 2008, Windows Server 2008 R2, and
Windows Server 2012
The minimum .NET version required is 4.0, and for development you need the following:
• Windows PowerShell 2.0. Windows PowerShell is a task-based, command-line shell and
scripting language designed especially for system administration. The built-in Windows
commands, known as cmdlets, help you to manage your Windows environment as well as
other applications installed, such as the database SQL Server.
• Either Visual Studio 2010 Service Pack 1, Visual Web Developer Express 2010 Service Pack 1,
Visual Studio 2012, or Visual Studio Express 2012 for Web. The Express editions are free
downloads, and the only difference from the paid versions is that they are missing certain
features, such as add-ins, an extended set of project templates, XML and UML features,
performance and analysis features, and so on.
Using Web Platform Installer
As previously mentioned, all versions of Visual Studio 2012 already include ASP.NET MVC 4. If you instead have Visual
Studio 2010 installed, either Express or another version, you need to follow the instructions in this section if you want
to include support for developing ASP.NET MVC 4 applications.
You can download Web PI from http://bit.ly/DownloadWebPI. Once you have downloaded it, run the
executable, which opens the interface shown in Figure 2-1. Note that WebPI’s interface is divided in three areas, top,
middle, and bottom. The top area includes the general categories of components and a search box. The middle area
is divided into two sections. The section on the left is a submenu of the category selected in the top area. Whichever
item you select in the submenu filters the components available in the section on the right. The Install column on
the right identifies whether the particular component is already installed on your system; if it isn’t, you can click the
Add button to add the component to the list of components to install. Finally, the bottom area provides a summary
count of the components to be installed, an Options link to further customize WebPI (such as the components feed and
interface language), an Install button (which is enabled once there are components selected for installation), and an
Exit button to quit the Web PI tool.
www.it-ebooks.info
Chapter 2 ■ Installing ASP.NET MVC 4
13
Figure 2-1 shows the Web Platform Installer window with the Products category selected. With the Products
category selected, choose the Frameworks submenu, as shown, and scroll down the list on the right to find the
component ASP.NET MVC 4 with Language Packs. The date of the installer release is indicated there too. Once you
locate the component, click the “Add” button to its right to instruct WebPI that you want the component
to be installed.
After you’ve added the component to the install list, you can click the link “Items to be installed” at the bottom
of the window to see what exactly will be installed, including all the dependencies. The resulting window is shown in
Figure 2-2. Click Close to return to the Web PI window.
Figure 2-1. Locating ASP.NET MVC 4 in Web PI for installation
Figure 2-2. Packages to be installed. The list of dependencies will vary based on what is already installed on the system
www.it-ebooks.info
Chapter 2 ■ Installing ASP.NET MVC 4
14
Now that everything is ready for installation, click the Install button to kickoff the installation, which is composed
of four steps:
• Prerequisites: This step shows you what will be installed, just as you saw in Figure 2-2.
The difference here is that you need to accept the licenses associated with the selected
components, as shown in Figure 2-3. Click the “I Accept” button and you are taken to the
second step, Install.
Figure 2-3. WebPI Prerequisites step
• Install: This step is simple and requires no interaction (see Figure 2-4). WebPI downloads the
required components and proceeds to install them. After everything is complete, you move
automatically to the Configure step.
www.it-ebooks.info
Chapter 2 ■ Installing ASP.NET MVC 4
15
• Configure: Depending on the selected components, additional configuration is required, such as
the definition of a port to host an application or any other type of configuration. All that is done
during the Configure step. Once all the configuration options are set, you are taken to the Finish step.
• Finish: This step shows the summary of the installations and offers you only one option,
“Finish,” as shown in Figure 2-5. Click “Finish” and the installation wizard will take you back to
WebPI, where you can select and install other components.
Figure 2-4. WebPI Install step
Figure 2-5. WebPI Finish step
www.it-ebooks.info
Chapter 2 ■ Installing ASP.NET MVC 4
16
Using the Stand-alone Installer
If you choose not to use the Web Platform Installer to install ASP.NET MVC 4, your other option with Visual Studio 2010
(either Express or another version) is to use the stand-alone installer.
As described earlier in the chapter, the stand-alone installer is an executable file that you download from
http://bit.ly/DownloadMVC4, shown in Figure 2-6. The advantage of the installer file is that it runs offline, so after
you download the file, you can disconnect from the Internet (if you need to) and share the file using any offline
method, such as USB keys.
Figure 2-6. Download page for the stand-alone installer
After you download the file, just double-click it and it will run, as shown in Figure 2-7. The process is really
simple. Select the “I agree to the license terms and conditions” check box to enable the Install button. Click the
“Install” button, and the program handles all the installation tasks. When it finishes, it prompts you to exit.
www.it-ebooks.info
Chapter 2 ■ Installing ASP.NET MVC 4
17
Installing ASP.NET MVC 4 Server Components
Let’s look now at the server that will host the application once we finish the development. Just as we needed to install
ASP.NET MVC 4 on the development machine in order to develop applications, we need to install it on the server so
that it can host the applications. In the server you also use one of the two available methods to install ASP.NET MVC 4,
the stand-alone installer or Web PI.
Installing ASP.NET MVC 4 on a server is different from installing it on your development machine in the sense that
the stand-alone installer (or WebPI) will skip installation of the development tools, recognizing that you’re installing
it on a server and that the operating system is different (e.g., Windows Server 2012). By making this distinction and
skipping unnecessary components, the server ends up having only the components that it needs to host and serve
ASP.NET MVC 4 applications.
An additional advantage of installing ASP.NET MVC 4 on the server is that the required assemblies are registered
in the Global Assembly Cache (GAC), which means that any web site that runs on ASP.NET MVC 4 in that server now
has the required assemblies available because the GAC works as a repository of assemblies for the whole server, not
just for individual applications
The limited component installation is also important for security and performance considerations, because
administrators don’t want any unnecessary software on the servers—and definitely don’t want development tools on
the server. The problem with installing development tools on the server is that they sometimes open network ports
and/or enable services that otherwise will be closed or turned off, and that increases the risks of security breaches
and performance problems.

Day 8 - ASP.NET MVC - Reference


ClassDescription
AcceptVerbsAttributeRepresents an attribute that specifies which HTTP verbs an action method will respond to.
ActionDescriptorProvides information about an action method, such as its name, controller, parameters, attributes, and filters.
ActionExecutedContextProvides the context for the ActionExecuted method of the ActionFilterAttribute class.
ActionExecutingContextProvides the context for the ActionExecuting method of the ActionFilterAttribute class.
ActionFilterAttributeRepresents the base class for filter attributes.
ActionMethodSelectorAttributeRepresents an attribute that is used to influence the selection of an action method.
ActionNameAttributeRepresents an attribute that is used for the name of an action.
ActionNameSelectorAttributeRepresents an attribute that affects the selection of an action method.
ActionResultEncapsulates the result of an action method and is used to perform a framework-level operation on behalf of the action method.
AdditionalMetadataAttributeProvides a class that implements the IMetadataAware interface in order to support additional metadata.
AjaxHelperRepresents support for rendering HTML in AJAX scenarios within a view.
AjaxHelper(Of TModel)Represents support for rendering HTML in AJAX scenarios within a strongly typed view.
AjaxRequestExtensionsRepresents a class that extends the HttpRequestBase class by adding the ability to determine whether an HTTP request is an AJAX request.
AllowHtmlAttributeAllows a request to include HTML markup during model binding by skipping request validation for the property. (It is strongly recommended that your application explicitly check all models where you disable request validation in order to prevent script exploits.)
AreaRegistrationProvides a way to register one or more areas in an ASP.NET MVC application.
AreaRegistrationContextEncapsulates the information that is required in order to register an area within an ASP.NET MVC application.
AssociatedMetadataProviderProvides an abstract class to implement a metadata provider.
AssociatedValidatorProviderProvides an abstract class for classes that implement a validation provider.
AsyncControllerProvides the base class for asynchronous controllers.
AsyncTimeoutAttributeRepresents an attribute that is used to set the timeout value, in milliseconds, for an asynchronous method.
AuthorizationContextEncapsulates the information that is required for using an AuthorizeAttribute attribute.
AuthorizeAttributeRepresents an attribute that is used to restrict access by callers to an action method.
BindAttributeRepresents an attribute that is used to provide details about how model binding to a parameter should occur.
BuildManagerCompiledViewRepresents the base class for views that are compiled by the BuildManager class before being rendered by a view engine.
BuildManagerViewEngineProvides a base class for view engines.
ByteArrayModelBinderMaps a browser request to a byte array.
ChildActionOnlyAttributeRepresents an attribute that is used to indicate that an action method should be called only as a child action.
ChildActionValueProviderRepresents a value provider for values from child actions.
ChildActionValueProviderFactoryRepresents a factory for creating value provider objects for child actions.
ClientDataTypeModelValidatorProviderReturns the client data-type model validators.
CompareAttributeProvides an attribute that compares two properties of a model.
ContentResultRepresents a user-defined content type that is the result of an action method.
ControllerProvides methods that respond to HTTP requests that are made to an ASP.NET MVC Web site.
ControllerActionInvokerRepresents a class that is responsible for invoking the action methods of a controller.
ControllerBaseRepresents the base class for all MVC controllers.
ControllerBuilderRepresents a class that is responsible for dynamically building a controller.
ControllerContextEncapsulates information about an HTTP request that matches specified RouteBase and ControllerBase instances.
ControllerDescriptorEncapsulates information that describes a controller, such as its name, type, and actions.
ControllerInstanceFilterProviderAdds the controller to the FilterProviderCollection instance.
CustomModelBinderAttributeRepresents an attribute that invokes a custom model binder.
DataAnnotationsModelMetadataProvides a container for common metadata, for the DataAnnotationsModelMetadataProvider class, and for the DataAnnotationsModelValidator class for a data model.
DataAnnotationsModelMetadataProviderImplements the default model metadata provider for ASP.NET MVC.
DataAnnotationsModelValidatorProvides a model validator.
DataAnnotationsModelValidator(Of TAttribute)Provides a model validator for a specified validation type.
DataAnnotationsModelValidatorProviderImplements the default validation provider for ASP.NET MVC.
DataErrorInfoModelValidatorProviderProvides a container for the error-information model validator.
DefaultControllerFactoryRepresents the controller factory that is registered by default.
DefaultModelBinderMaps a browser request to a data object. This class provides a concrete implementation of a model binder.
DefaultViewLocationCacheRepresents a memory cache for view locations.
DependencyResolverProvides a registration point for dependency resolvers that implement IDependencyResolver or the Common Service Locator IServiceLocator interface.
DependencyResolverExtensionsProvides a type-safe implementation of GetService and GetServices.
DictionaryValueProvider(Of TValue)Represents the base class for value providers whose values come from a collection that implements the IDictionary(Of TKey, TValue) interface.
EmptyModelMetadataProviderProvides an empty metadata provider for data models that do not require metadata.
EmptyModelValidatorProviderProvides an empty validation provider for models that do not require a validator.
EmptyResultRepresents a result that does nothing, such as a controller action method that returns nothing.
ExceptionContextProvides the context for using the HandleErrorAttribute class.
ExpressionHelperProvides a helper class to get the model name from an expression.
FieldValidationMetadataProvides a container for client-side field validation metadata.
FileContentResultSends the contents of a binary file to the response.
FilePathResultSends the contents of a file to the response.
FileResultRepresents a base class that is used to send binary file content to the response.
FileStreamResultSends binary content to the response by using a Stream instance.
FilterRepresents a metadata class that contains a reference to the implementation of one or more of the filter interfaces, the filter's order, and the filter's scope.
FilterAttributeRepresents the base class for action and result filter attributes.
FilterAttributeFilterProviderDefines a filter provider for filter attributes.
FilterInfoEncapsulates information about the available action filters.
FilterProviderCollectionRepresents the collection of filter providers for the application.
FilterProvidersProvides a registration point for filters.
FormCollectionContains the form value providers for the application.
FormContextEncapsulates information that is required in order to validate and process the input data from an HTML form.
FormValueProviderRepresents a value provider for form values that are contained in a NameValueCollection object.
FormValueProviderFactoryRepresents a class that is responsible for creating a new instance of a form-value provider object.
GlobalFilterCollectionRepresents a class that contains all the global filters.
GlobalFiltersRepresents the global filter collection.
HandleErrorAttributeRepresents an attribute that is used to handle an exception that is thrown by an action method.
HandleErrorInfoEncapsulates information for handling an error that was thrown by an action method.
HiddenInputAttributeRepresents an attribute that is used to indicate whether a property or field value should be rendered as a hidden input element.
HtmlHelperRepresents support for rendering HTML controls in a view.
HtmlHelper(Of TModel)Represents support for rendering HTML controls in a strongly typed view.
HttpDeleteAttributeRepresents an attribute that is used to restrict an action method so that the method handles only HTTP DELETE requests.
HttpFileCollectionValueProviderRepresents a value provider to use with values that come from a collection of HTTP files.
HttpFileCollectionValueProviderFactoryRepresents a class that is responsible for creating a new instance of an HTTP file collection value provider object.
HttpGetAttributeRepresents an attribute that is used to restrict an action method so that the method handles only HTTP GET requests.
HttpNotFoundResultDefines an object that is used to indicate that the requested resource was not found.
HttpPostAttributeRepresents an attribute that is used to restrict an action method so that the method handles only HTTP POST requests.
HttpPostedFileBaseModelBinderBinds a model to a posted file.
HttpPutAttributeRepresents an attribute that is used to restrict an action method so that the method handles only HTTP PUT requests.
HttpRequestExtensionsExtends the HttpRequestBase class that contains the HTTP values that were sent by a client during a Web request.
HttpStatusCodeResultProvides a way to return an action result with a specific HTTP response status code and description.
HttpUnauthorizedResultRepresents the result of an unauthorized HTTP request.
JavaScriptResultSends JavaScript content to the response.
JsonResultRepresents a class that is used to send JSON-formatted content to the response.
JsonValueProviderFactoryEnables action methods to send and receive JSON-formatted text and to model-bind the JSON text to parameters of action methods.
LinqBinaryModelBinderMaps a browser request to a LINQ Binary object.
ModelBinderAttributeRepresents an attribute that is used to associate a model type to a model-builder type.
ModelBinderDictionaryRepresents a class that contains all model binders for the application, listed by binder type.
ModelBinderProviderCollectionProvides a container for model binder providers.
ModelBinderProvidersProvides a container for model binder providers.
ModelBindersProvides global access to the model binders for the application.
ModelBindingContextProvides the context in which a model binder functions.
ModelClientValidationEqualToRuleProvides a container for an equality validation rule that is sent to the browser.
ModelClientValidationRangeRuleProvides a container for a range-validation rule that is sent to the browser.
ModelClientValidationRegexRuleProvides a container for a regular-expression client validation rule that is sent to the browser.
ModelClientValidationRemoteRuleProvides a container for a remote validation rule that is sent to the browser.
ModelClientValidationRequiredRuleProvides a container for client validation for required field.
ModelClientValidationRuleProvides a base class container for a client validation rule that is sent to the browser.
ModelClientValidationStringLengthRuleProvides a container for a string-length validation rule that is sent to the browser.
ModelErrorRepresents an error that occurs during model binding.
ModelErrorCollectionA collection of ModelError instances.
ModelMetadataProvides a container for common metadata, for the ModelMetadataProvider class, and for the ModelValidator class for a data model.
ModelMetadataProviderProvides an abstract base class for a custom metadata provider.
ModelMetadataProvidersProvides a container for the current ModelMetadataProvider instance.
ModelStateEncapsulates the state of model binding to a property of an action-method argument, or to the argument itself.
ModelStateDictionaryRepresents the state of an attempt to bind a posted form to an action method, which includes validation information.
ModelValidationResultProvides a container for a validation result.
ModelValidatorProvides a base class for implementing validation logic.
ModelValidatorProviderProvides a list of validators for a model.
ModelValidatorProviderCollectionProvides a container for a list of validation providers.
ModelValidatorProvidersProvides a container for the current validation provider.
MultiSelectListRepresents a list of items that users can select more than one item from.
MvcFilterWhen implemented in a derived class, provides a metadata class that contains a reference to the implementation of one or more of the filter interfaces, the filter's order, and the filter's scope.
MvcHandlerSelects the controller that will handle an HTTP request.
MvcHtmlStringRepresents an HTML-encoded string that should not be encoded again.
MvcHttpHandlerVerifies and processes an HTTP request.
MvcRouteHandlerCreates an object that implements the IHttpHandler interface and passes the request context to it.
MvcWebRazorHostFactoryCreates instances of MvcWebPageRazorHost files.
NameValueCollectionExtensionsExtends a NameValueCollection object so that the collection can be copied to a specified dictionary.
NameValueCollectionValueProviderRepresents the base class for value providers whose values come from a NameValueCollection object.
NoAsyncTimeoutAttributeProvides a convenience wrapper for the AsyncTimeoutAttribute attribute.
NonActionAttributeRepresents an attribute that is used to indicate that a controller method is not an action method.
OutputCacheAttributeRepresents an attribute that is used to mark an action method whose output will be cached.
ParameterBindingInfoEncapsulates information for binding action-method parameters to a data model.
ParameterDescriptorContains information that describes a parameter.
PartialViewResultRepresents a base class that is used to send a partial view to the response.
PreApplicationStartCodeProvides a registration point for ASP.NET Razor pre-application start code.
QueryStringValueProviderRepresents a value provider for query strings that are contained in a NameValueCollection object.
QueryStringValueProviderFactoryRepresents a class that is responsible for creating a new instance of a query-string value-provider object.
RangeAttributeAdapterProvides an adapter for the RangeAttribute attribute.
RazorViewRepresents the class used to create views that have Razor syntax.
RazorViewEngineRepresents a view engine that is used to render a Web page that uses the ASP.NET Razor syntax.
RedirectResultControls the processing of application actions by redirecting to a specified URI.
RedirectToRouteResultRepresents a result that performs a redirection by using the specified route values dictionary.
ReflectedActionDescriptorContains information that describes a reflected action method.
ReflectedControllerDescriptorContains information that describes a reflected controller.
ReflectedParameterDescriptorContains information that describes a reflected action-method parameter.
RegularExpressionAttributeAdapterProvides an adapter for the RegularExpressionAttribute attribute.
RemoteAttributeProvides an attribute that uses the jQuery validation plug-in remote validator.
RequiredAttributeAdapterProvides an adapter for the RequiredAttributeAttribute attribute.
RequireHttpsAttributeRepresents an attribute that forces an unsecured HTTP request to be re-sent over HTTPS.
ResultExecutedContextProvides the context for the OnResultExecuted method of the ActionFilterAttribute class.
ResultExecutingContextProvides the context for the OnResultExecuting method of the ActionFilterAttribute class.
RouteCollectionExtensionsExtends a RouteCollection object for MVC routing.
RouteDataValueProviderRepresents a value provider for route data that is contained in an object that implements the IDictionary(Of TKey, TValue) interface.
RouteDataValueProviderFactoryRepresents a factory for creating route-data value provider objects.
SelectListRepresents a list that lets users select one item.
SelectListItemRepresents the selected item in an instance of the SelectList class.
SessionStateAttributeSpecifies the session state of the controller.
SessionStateTempDataProviderProvides session-state data to the current TempDataDictionary object.
StringLengthAttributeAdapterProvides an adapter for the StringLengthAttribute attribute.
TempDataDictionaryRepresents a set of data that persists only from one request to the next.
TemplateInfoEncapsulates information about the current template context.
UrlHelperContains methods to build URLs for ASP.NET MVC within an application.
UrlParameterRepresents an optional parameter that is used by the MvcHandler class during routing.
ValidatableObjectAdapterProvides an object adapter that can be validated.
ValidateAntiForgeryTokenAttributeRepresents an attribute that is used to prevent forgery of a request.
ValidateInputAttributeRepresents an attribute that is used to mark action methods whose input must be validated.
ValueProviderCollectionRepresents the collection of value-provider objects for the application.
ValueProviderDictionaryObsolete. Represents a dictionary of value providers for the application.
ValueProviderFactoriesRepresents a container for value-provider factory objects.
ValueProviderFactoryRepresents a factory for creating value-provider objects.
ValueProviderFactoryCollectionRepresents the collection of value-provider factories for the application.
ValueProviderResultRepresents the result of binding a value (such as from a form post or query string) to an action-method argument property, or to the argument itself.
ViewContextEncapsulates information that is related to rendering a view.
ViewDataDictionaryRepresents a container that is used to pass data between a controller and a view.
ViewDataDictionary(Of TModel)Represents a container that is used to pass strongly typed data between a controller and a view.
ViewDataInfoEncapsulates information about the current template content that is used to develop templates and about HTML helpers that interact with templates.
ViewEngineCollectionRepresents a collection of view engines that are available to the application.
ViewEngineResultRepresents the result of locating a view engine.
ViewEnginesRepresents a collection of view engines that are available to the application.
ViewMasterPageRepresents the information that is needed to build a master view page.
ViewMasterPage(Of TModel)Represents the information that is required in order to build a strongly typed master view page.
ViewPageRepresents the properties and methods that are needed to render a view as a Web Forms page.
ViewPage(Of TModel)Represents the information that is required in order to render a strongly typed view as a Web Forms page.
ViewResultRepresents a class that is used to render a view by using an IView instance that is returned by an IViewEngine object.
ViewResultBaseRepresents a base class that is used to provide the model to the view and then render the view to the response.
ViewStartPageProvides an abstract class that can be used to implement a view start (master) page.
ViewTemplateUserControlProvides a container for TemplateInfo objects.
ViewTemplateUserControl(Of TModel)Provides a container for TemplateInfo objects.
ViewTypeRepresents the type of a view.
ViewUserControlRepresents the information that is needed to build a user control.
ViewUserControl(Of TModel)Represents the information that is required in order to build a strongly typed user control.
VirtualPathProviderViewEngineRepresents an abstract base-class implementation of the IViewEngine interface.
WebFormViewRepresents the information that is needed to build a Web Forms page in ASP.NET MVC.
WebFormViewEngineRepresents a view engine that is used to render a Web Forms page to the response.
WebViewPageRepresents the properties and methods that are needed in order to render a view that uses ASP.NET Razor syntax.
WebViewPage(Of TModel)Represents the properties and methods that are needed in order to render a view that uses ASP.NET Razor syntax.

Interfaces

InterfaceDescription
IActionFilterDefines the methods that are used in an action filter.
IActionInvokerDefines the contract for an action invoker, which is used to invoke an action in response to an HTTP request.
IAuthorizationFilterDefines the methods that are required for an authorization filter.
IClientValidatableProvides a way for the ASP.NET MVC validation framework to discover at run time whether a validator has support for client validation.
IControllerDefines the methods that are required for a controller.
IControllerActivatorProvides fine-grained control over how controllers are instantiated using dependency injection.
IControllerFactoryDefines the methods that are required for a controller factory.
IDependencyResolverDefines the methods that simplify service location and dependency resolution.
IExceptionFilterDefines the methods that are required for an exception filter.
IFilterProviderProvides an interface for finding filters.
IMetadataAwareProvides an interface for exposing attributes to the AssociatedMetadataProvider class.
IModelBinderDefines the methods that are required for a model binder.
IModelBinderProviderDefines methods that enable dynamic implementations of model binding for classes that implement the IModelBinder interface.
IMvcFilterDefines members that specify the order of filters and whether multiple filters are allowed.
IResultFilterDefines the methods that are required for a result filter.
IRouteWithAreaAssociates a route with an area in an ASP.NET MVC application.
ITempDataProviderDefines the contract for temporary-data providers that store data that is viewed on the next request.
IUnvalidatedValueProviderRepresents an IValueProvider interface that can skip request validation.
IValueProviderDefines the methods that are required for a value provider in ASP.NET MVC.
IViewDefines the methods that are required for a view.
IViewDataContainerDefines the methods that are required for a view data dictionary.
IViewEngineDefines the methods that are required for a view engine.
IViewLocationCacheDefines the methods that are required in order to cache view locations in memory.
IViewPageActivatorProvides fine-grained control