MVC 5 AND MVC6 INTERVIEW QUESTIONS AND
ANSWERS
What is the difference between each version of MVC 2,3,4, 5 and 6?
MVC
6
ASP.NET MVC and Web API has been merged in to one.
Dependency injection is inbuilt and part of MVC.
Side by side - deploy the runtime and framework with
your application
Everything packaged with NuGet, Including the .NET
runtime itself.
New JSON based project structure.
No need to recompile for every change. Just hit save
and refresh the browser.
Compilation done with the new Roslyn real-time
compiler.
vNext is Open Source via the .NET Foundation and is
taking public contributions.
vNext (and Rosyln) also runs on Mono, on both Mac
and Linux today.
MVC
5
One ASP.NET
Attribute based routing
Asp.Net Identity
Bootstrap in the MVC template
Authentication Filters
Filter overrides
MVC
4
ASP.NET Web API
Refreshed and modernized default project templates
New mobile project template
Many new features to support mobile apps
Enhanced support for asynchronous methods
MVC
3
Razor
Readymade project templates
HTML 5 enabled templates
Support for Multiple View Engines
JavaScript and Ajax
Model Validation Improvements
MVC
2
Client-Side Validation
Templated Helpers
Areas
Asynchronous Controllers
Html.ValidationSummary Helper Method
DefaultValueAttribute in Action-Method Parameters
Binding Binary Data with Model Binders
DataAnnotations Attributes
Model-Validator Providers
New RequireHttpsAttribute Action Filter
Templated Helpers
Display Model-Level Errors
What are the new features in Asp.Net MVC5 ?
§ Introducing One ASP.NET
§ Introducing Asp.Net One Identity
§ Introducing Bootstrap in the MVC template
§ Introducing Filter overrides (Overriding filters)
§ Introducing Authentication Filters
§ Introducing Web API 2
§ Introducing OAuth 2.0 Authorization in MVC 5
§ OData Improvements in MVC
5(Full support
for $select, $expand, $batch, and $value)
§ Introducing ASP.NET SignalR 2.0
ASP.NET
WEB API 2
§ Attribute routing
What is One ASP.NET ?
Web MVC project templates integrated with the new
One ASP.NET experience. we can customize our MVC project and configure
authentication by using One ASP.NET project creation wizard.
One ASP.NET
=> Asp.Net + Site +
Services + Web Forms + Web Pages + Single Page + MVC + Web API + Single R
What is the structure of
ASP.NET MVC 5 and release’s ?
What’s
Bootstrap is new MVC 5 ?
MVC project template is updated in MVC 5 to use
Bootstrap for better look and feel. Now you can easily customize. For more
information
Bootstrap In Short:
§ With the updated MVC
template, You can do Customization very easily
§ Better look and feel.
What is ASP.NET Web API 2 ?
Self-Hosted Web API
§ Multiple Routes (Get
Routes) on an Action
§ Route Defaults (With
Default Parameters)
§ Route Parameters as
optional
§ Route Constraints
§ Chaining and Combining
with Defaults and Optionals
§ Named Routes
§ Route Prefixe (New
Attribute)
[RoutePrefix(“Blog/{BlogId}”)]
public class BlogController : ControllerBase
{
GET(“Blogs”)]
public ActionResult Index(int BlogId) { /* … */ }
}
What
are new updates in ASP.NET MVC 5 Areas ?
§ Overriding the Area URL
Prefix
§ Ignoring Area URLs for
Certain Routes
What
are advanced features of ASP.NET MVC 5 ?
§ Localizing URL’s
§ Newly Added
provider FluentTranslationProvider
§ Newly Route Convention
Attribute
§ Subdomain Routing
LOCALIZING
URL’S
We can localize our URL’s using an AttribtueRouting
translation provider. A translation provider is useful to work against resx
files, databases, etc. To create our own, simply extend
routes.MapAttributeRoutes(myConfig
=>
{
myConfig.AddTranslationProvider(new MyCustomTranslationProvider());
});
ROUTE
CONVENTION ATTRIBUTE ATTRIBUTE
public class
MyRouteConventionAttribute : RouteConventionAttributeBase
{
public override IEnumerable
GetRouteAttributes(MethodInfo actionMethod)
{
// TODO: Yield IRouteAttributes (GET/POST/PUT/DELETE/Route).
}
}
SUBDOMAIN
ROUTING
Wc can map our ASP.NET MVC areas to subdomains by
using the Subdomain property of the RouteAreaAttribute. Doing so ensures that
the routes for the area are matched only when requests are made to the specified
subdomain. Here’s how:
[RouteArea(“Users”, Subdomain =
“users”)]
public class SubdomainController : Controller
{
[GET(“”)]
public ActionResult Index() { /* … */ }
}
Is
OAuth 2.0 support’s for Web API and Single Page Application ?
The MVC Web API and Single Page Application project
templates now support authorization using OAuth 2.0. OAuth 2.0 is a
authorization framework for authorizing client access to protected resources.
It works for a variety of clients like for different browsers & mobile devices.
What
are the OData Improvements ?
Full Support for $select, $expand, $batch &
$value
Much improved extensibility
Type less support (No need to define CLR types)
Explain
what is the difference between View and Partial View?
View
Partial View
- It contains the
layout page
- Before any view is
rendered, viewstart page is rendered
- View might have
markup tags like body, html, head, title, meta etc.
- View is not
lightweight as compare to Partial View
- It does not
contain the layout page
- Partial view does
not verify for a viewstart.cshtml. We cannot put common code for a
partial view within the viewStart.cshtml.page
- Partial view is
designed specially to render within the view and just because of that it
does not consist any mark up
- We can pass a
regular view to the RenderPartial method
Mention two instances where routing is not
implemented or required?
Two instance
where routing is not required are
· When a physical file is
found that matches the URL pattern
· When routing is disabled
for a URL pattern
Mention what “beforFilter()”,“beforeRender” and
“afterFilter” functions do in Controller?
· beforeFilter(): This function is
run before every action in the controller. It’s the right place to check for an
active session or inspect user permissions.
· beforeRender(): This function is
called after controller action logic, but before the view is rendered. This
function is not often used, but may be required If you are calling render()
manually before the end of a given action
· afterFilter(): This function is
called after every controller action, and after rendering is done. It is the
last controller method to run
MVC 6 is the latest version which is also termed as
ASP VNEXT.
Can we map multiple URL’s to the same action?
Yes, you can, you just need to make two entries with
different key names and specify the same controller and action.
This is a feature introduced in MVC 5. By using the
"Route" attribute we can define the URL structure. For example in the
below code we have decorated the "GotoAbout" action with the route
attribute. The route attribute says that the "GotoAbout" can be invoked
using the URL structure "Users/about".
public class
HomeController : Controller
{
[Route("Users/about")]
public ActionResult GotoAbout()
{
return View();
}
}
Does
the unit testing of an MVC application is possible without running controllers
in an ASP.NET process?
In
an MVC application, all the features are based on interface. So, it is easy to
unit test a MVC application. And it is to note that, in MVC application
there is no need of running the controllers for unit testing.
ASP.NET MVC6 | ASP.NET vNext
§ Single Programming
Model for
ASP.NET MVC and ASP.NET Web API.
§ Optimized for Cloud Computing.
§ Supporting side by side deployment of runtime and framework along
with application.
§ Out of the box support
for dependency injection.
§ vNext is Open Source and supports running on multiple platforms
including Linux and Mac.
§ New JSON-based project Extension.
§ In order to dynamically
compile code, Roslyn compiler is used.
Features of ASP.NET vNext
1. ASP.NET vNext includes new cloud-optimized versions
of MVC, Web API, Web Pages, SignalR, and Entity Framework.
2. MVC, Web API and Web Pages have been merged into one
framework, called MVC 6. This will follow common programming approach between
all these three i.e. a single programming model for Web sites and services.
For example, there is
unified controller, routing concepts, action selection, filters, model binding,
and so on. In this way, You will have a single controller that returns both MVC
views and formatted Web API responses, on the same HTTP verb.
3. MVC 6 has no dependency on System.Web since it was
quite expensive. A typical HttpContext object graph can consume 30K of memory
per request and working with small JSON-style requests this is very costly.
With MVC 6 it is reduced to roughly 2K. The result is a leaner framework, with
faster startup time and lower memory consumption.
4. ASP.NET vNext has new project extension project.json to list all the
dependencies for the application and startup class in place of Global.asax.
5. ASP.NET vNext apps are cloud ready by design.
Services such as session state and caching will adjust their behavior depending
on hosting environment either it is cloud or a traditional hosting environment.
It uses dependency injection behind the scenes to provide your app with the
correct implementation for these services for cloud or a traditional hosting
environment. In this way, it will easy to move your app from on-premises to the
cloud, since you need not to change your code.
6. .NET next version, .NET vNext is host agnostic.
Hence you can host your ASP.NET vNEXT app in IIS, or self-host in a custom
process.
7. .NET vNext support true side-by-side deployment. If
your app is using cloud-optimized subset of .NET vNext, you can deploy all of
your dependencies including the .NET vNext (cloud optimized) by uploading bin
to hosting environment. In this way you can update your app without affecting
other applications on the same server.
8. Dependency injection is built into the framework.
Now, you can use your preferred IoC container to register dependencies.
9. .NET vNext use the Roslyn compiler to compile code
dynamically. Hence you will be able to edit a code file and can see the changes
by refreshing the browser; without stopping or rebuilding the project.
10. .NET vNext is
open source and cross platform. It can run on Mono, on Mac and Linux.
Let's
see what is new in ASP.NET MVC 6
Full Framework vs. Cloud-optimized Framework
In MVC 6 Microsoft
removed the dependency of System.Web.Dll from MVC6 because it's so
expensive that typically it consume 30k of memory per request and response,
whereas now MVC 6 only requires 2k of memory per request and the response is a
very small memory consumtion.
The advantage of using
the cloud-optimized framework is that we can include a copy of the mono CLR
with your website. For the sake of one website we do not need to upgrade the
.NET version on the entire machine. A different version of the CLR for a
different website running side by side.
MVC 6 is a part of
ASP.NET 5 that has been designed for cloud-optimized applications. The runtime
automatically picks the correct version of the library when our MVC application
is deployed to the cloud.
The Core CLR is also supposed to be tuned with a
high resource-efficient optimization.
Microsoft has made many MVC, Web API,
WebPage and SignalLr peices we call MVC 6.
Most of the problems are solved using the Roslyn
Compiler. In ASP.NET vNext uses the Roslyn Compiler. Using the Roslyn Compiler
we do not need to compile the application, it automatically compiles the
application code. You will edit a code file and can then see the changes by
refreshing the browser without stopping or rebuilding the project.
Run
on hosts other than IIS
Where we use MVC5 we can host it on an IIS server and we can also run it on top
of an ASP. Net Pipeline, on the other hand MVC 6 has a feature that makes it
better and that feature is itself hosted on an IIS server and a self-user
pipeline.
Environment based configuration system
The configuration system provides an environment to easily deploy the
application on the cloud. Our application works just like a configuration
provider. It helps to retrieve the value from the various configuration sources
like XML file.
MVC6 includes a new environment-based configuration system. Unlike something
else it depends on just the Web.Config file in the previous version.
Dependency
injection
Using the IServiceProvider interface we can easily add our own
dependency injection container. We can replace the default implementation with
our own container.
Supports
OWIN
We have complete control over the composable pipeline in MVC 6 applications.
MVC 6 supports the OWIN abstraction.
Important components of an MVC6 application
The is a new file type in MVC6 as in the following:
The preceding files are new in MVC 6. Let's see what each of these files
contain.
Config.Json
This file contains the application configuration in various places. We can
define our application configuration, not just this file. There is no need to
be concerned about how to connect to various sources to get the confutation
value.
In the following code we add a connection string in the Config.json file.
1. {
2. "Data": {
3. "DefaultConnection": {
4. "ConnectionString": "Server=server_name;Database=database_name;Trusted_Connection=True;MultipleActiveResultSets=true"
5. }
6. },
Project.json
This file contains the build information as well as
project dependencies. It can contain the commands used by the application.
1. {
2.
3. "webroot": "wwwroot",
4. "version": "1.0.0-*",
5. "dependencies": {
6. "Microsoft.AspNet.Mvc": "6.0.0-beta1",
7. "Microsoft.AspNet.Server.IIS": "1.0.0-alpha4",
8. },
9. "commands": {
10. /* Change the port number when you are self hosting this application */
11. "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
12.
13. },
14. "frameworks": {
15. "aspnet50": { },
16. "aspnetcore50": { }
17. },
18.
19. } }
Startup.cs
The Application Builder is used as a parameter when
the configure method is used when the Startup class is used by the host.
Global.json
Define the location for the project reference so that the projects can
reference each other.
Defining the Request Pipeline
If we look at the Startup.cs it contains a startup
method.
1. public Startup(IHostingEnvironment env)
2. {
3. // Setup configuration sources.
4. var Configuration = new Configuration();
5. Configuration.AddJsonFile("config.json");
6. Configuration .AddEnvironmentVariables();
7. }
Create
a Controller
If we look at the controller it is similar to the
controller in a MVC 5 application.
1. public class HomeController : Controller
2. {
3. public IActionResult Index()
4. {
5. return View();
6. }
The namespace for MVC6 is Microsoft.ASPNET.MVC
unlike the System.Web.MVC in the previous version. That is a big difference. In
MVC 6 the application does not need to be derived from the controller class. In
our controller there are many defaults functionalities. Most of the time we
might need to derive from the controller class, but if we do not need access to
all of the functionally provided by the controller class, we can define our
controller class.
1. public class HomeController : Controller
2. {
3. public ActionResult Index()
4. {
5. return View();
6. }
7. public string atul()
8. {
9. return "hello i am mvc6";
10.
11. }
If you execute the preceding method we may see
the following page.
MVC 5 AND MVC6 INTERVIEW QUESTIONS AND
ANSWERS
What is the difference between each version of MVC 2,3,4, 5 and 6?
MVC
6
ASP.NET MVC and Web API has been merged in to one.
Dependency injection is inbuilt and part of MVC.
Side by side - deploy the runtime and framework with
your application
Everything packaged with NuGet, Including the .NET
runtime itself.
New JSON based project structure.
No need to recompile for every change. Just hit save
and refresh the browser.
Compilation done with the new Roslyn real-time
compiler.
vNext is Open Source via the .NET Foundation and is
taking public contributions.
vNext (and Rosyln) also runs on Mono, on both Mac
and Linux today.
MVC
5
One ASP.NET
Attribute based routing
Asp.Net Identity
Bootstrap in the MVC template
Authentication Filters
Filter overrides
MVC
4
ASP.NET Web API
Refreshed and modernized default project templates
New mobile project template
Many new features to support mobile apps
Enhanced support for asynchronous methods
MVC
3
Razor
Readymade project templates
HTML 5 enabled templates
Support for Multiple View Engines
JavaScript and Ajax
Model Validation Improvements
MVC
2
Client-Side Validation
Templated Helpers
Areas
Asynchronous Controllers
Html.ValidationSummary Helper Method
DefaultValueAttribute in Action-Method Parameters
Binding Binary Data with Model Binders
DataAnnotations Attributes
Model-Validator Providers
New RequireHttpsAttribute Action Filter
Templated Helpers
Display Model-Level Errors
What are the new features in Asp.Net MVC5 ?
§ Introducing One ASP.NET
§ Introducing Asp.Net One Identity
§ Introducing Bootstrap in the MVC template
§ Introducing Filter overrides (Overriding filters)
§ Introducing Authentication Filters
§ Introducing Web API 2
§ Introducing OAuth 2.0 Authorization in MVC 5
§ OData Improvements in MVC
5(Full support
for $select, $expand, $batch, and $value)
§ Introducing ASP.NET SignalR 2.0
ASP.NET
WEB API 2
§ Attribute routing
What is One ASP.NET ?
Web MVC project templates integrated with the new
One ASP.NET experience. we can customize our MVC project and configure
authentication by using One ASP.NET project creation wizard.
One ASP.NET
=> Asp.Net + Site +
Services + Web Forms + Web Pages + Single Page + MVC + Web API + Single R
What is the structure of
ASP.NET MVC 5 and release’s ?
What’s
Bootstrap is new MVC 5 ?
MVC project template is updated in MVC 5 to use
Bootstrap for better look and feel. Now you can easily customize. For more
information
Bootstrap In Short:
§ With the updated MVC
template, You can do Customization very easily
§ Better look and feel.
What is ASP.NET Web API 2 ?
Self-Hosted Web API
§ Multiple Routes (Get
Routes) on an Action
§ Route Defaults (With
Default Parameters)
§ Route Parameters as
optional
§ Route Constraints
§ Chaining and Combining
with Defaults and Optionals
§ Named Routes
§ Route Prefixe (New
Attribute)
[RoutePrefix(“Blog/{BlogId}”)]
public class BlogController : ControllerBase
{
GET(“Blogs”)]
public ActionResult Index(int BlogId) { /* … */ }
}
public class BlogController : ControllerBase
{
GET(“Blogs”)]
public ActionResult Index(int BlogId) { /* … */ }
}
What
are new updates in ASP.NET MVC 5 Areas ?
§ Overriding the Area URL
Prefix
§ Ignoring Area URLs for
Certain Routes
What
are advanced features of ASP.NET MVC 5 ?
§ Localizing URL’s
§ Newly Added
provider FluentTranslationProvider
§ Newly Route Convention
Attribute
§ Subdomain Routing
LOCALIZING
URL’S
We can localize our URL’s using an AttribtueRouting
translation provider. A translation provider is useful to work against resx
files, databases, etc. To create our own, simply extend
routes.MapAttributeRoutes(myConfig
=>
{
myConfig.AddTranslationProvider(new MyCustomTranslationProvider());
});
{
myConfig.AddTranslationProvider(new MyCustomTranslationProvider());
});
ROUTE
CONVENTION ATTRIBUTE ATTRIBUTE
public class
MyRouteConventionAttribute : RouteConventionAttributeBase
{
public override IEnumerable
GetRouteAttributes(MethodInfo actionMethod)
{
// TODO: Yield IRouteAttributes (GET/POST/PUT/DELETE/Route).
}
}
{
public override IEnumerable
GetRouteAttributes(MethodInfo actionMethod)
{
// TODO: Yield IRouteAttributes (GET/POST/PUT/DELETE/Route).
}
}
SUBDOMAIN
ROUTING
Wc can map our ASP.NET MVC areas to subdomains by
using the Subdomain property of the RouteAreaAttribute. Doing so ensures that
the routes for the area are matched only when requests are made to the specified
subdomain. Here’s how:
[RouteArea(“Users”, Subdomain =
“users”)]
public class SubdomainController : Controller
{
[GET(“”)]
public ActionResult Index() { /* … */ }
}
public class SubdomainController : Controller
{
[GET(“”)]
public ActionResult Index() { /* … */ }
}
Is
OAuth 2.0 support’s for Web API and Single Page Application ?
The MVC Web API and Single Page Application project
templates now support authorization using OAuth 2.0. OAuth 2.0 is a
authorization framework for authorizing client access to protected resources.
It works for a variety of clients like for different browsers & mobile devices.
What
are the OData Improvements ?
Full Support for $select, $expand, $batch &
$value
Much improved extensibility
Type less support (No need to define CLR types)
Much improved extensibility
Type less support (No need to define CLR types)
Explain
what is the difference between View and Partial View?
View
|
Partial View
|
|
|
Mention two instances where routing is not
implemented or required?
Two instance
where routing is not required are
· When a physical file is
found that matches the URL pattern
· When routing is disabled
for a URL pattern
Mention what “beforFilter()”,“beforeRender” and
“afterFilter” functions do in Controller?
· beforeFilter(): This function is
run before every action in the controller. It’s the right place to check for an
active session or inspect user permissions.
· beforeRender(): This function is
called after controller action logic, but before the view is rendered. This
function is not often used, but may be required If you are calling render()
manually before the end of a given action
· afterFilter(): This function is
called after every controller action, and after rendering is done. It is the
last controller method to run
MVC 6 is the latest version which is also termed as
ASP VNEXT.
Can we map multiple URL’s to the same action?
Yes, you can, you just need to make two entries with
different key names and specify the same controller and action.
This is a feature introduced in MVC 5. By using the
"Route" attribute we can define the URL structure. For example in the
below code we have decorated the "GotoAbout" action with the route
attribute. The route attribute says that the "GotoAbout" can be invoked
using the URL structure "Users/about".
public class
HomeController : Controller
{
[Route("Users/about")]
public ActionResult GotoAbout()
{
return View();
}
}
Does
the unit testing of an MVC application is possible without running controllers
in an ASP.NET process?
In
an MVC application, all the features are based on interface. So, it is easy to
unit test a MVC application. And it is to note that, in MVC application
there is no need of running the controllers for unit testing.
ASP.NET MVC6 | ASP.NET vNext
§ Single Programming
Model for
ASP.NET MVC and ASP.NET Web API.
§ Optimized for Cloud Computing.
§ Supporting side by side deployment of runtime and framework along
with application.
§ Out of the box support
for dependency injection.
§ vNext is Open Source and supports running on multiple platforms
including Linux and Mac.
§ New JSON-based project Extension.
§ In order to dynamically
compile code, Roslyn compiler is used.
Features of ASP.NET vNext
1. ASP.NET vNext includes new cloud-optimized versions
of MVC, Web API, Web Pages, SignalR, and Entity Framework.
2. MVC, Web API and Web Pages have been merged into one
framework, called MVC 6. This will follow common programming approach between
all these three i.e. a single programming model for Web sites and services.
For example, there is
unified controller, routing concepts, action selection, filters, model binding,
and so on. In this way, You will have a single controller that returns both MVC
views and formatted Web API responses, on the same HTTP verb.
3. MVC 6 has no dependency on System.Web since it was
quite expensive. A typical HttpContext object graph can consume 30K of memory
per request and working with small JSON-style requests this is very costly.
With MVC 6 it is reduced to roughly 2K. The result is a leaner framework, with
faster startup time and lower memory consumption.
4. ASP.NET vNext has new project extension project.json to list all the
dependencies for the application and startup class in place of Global.asax.
5. ASP.NET vNext apps are cloud ready by design.
Services such as session state and caching will adjust their behavior depending
on hosting environment either it is cloud or a traditional hosting environment.
It uses dependency injection behind the scenes to provide your app with the
correct implementation for these services for cloud or a traditional hosting
environment. In this way, it will easy to move your app from on-premises to the
cloud, since you need not to change your code.
6. .NET next version, .NET vNext is host agnostic.
Hence you can host your ASP.NET vNEXT app in IIS, or self-host in a custom
process.
7. .NET vNext support true side-by-side deployment. If
your app is using cloud-optimized subset of .NET vNext, you can deploy all of
your dependencies including the .NET vNext (cloud optimized) by uploading bin
to hosting environment. In this way you can update your app without affecting
other applications on the same server.
8. Dependency injection is built into the framework.
Now, you can use your preferred IoC container to register dependencies.
9. .NET vNext use the Roslyn compiler to compile code
dynamically. Hence you will be able to edit a code file and can see the changes
by refreshing the browser; without stopping or rebuilding the project.
10. .NET vNext is
open source and cross platform. It can run on Mono, on Mac and Linux.
Let's
see what is new in ASP.NET MVC 6
Full Framework vs. Cloud-optimized Framework
Full Framework vs. Cloud-optimized Framework
In MVC 6 Microsoft
removed the dependency of System.Web.Dll from MVC6 because it's so
expensive that typically it consume 30k of memory per request and response,
whereas now MVC 6 only requires 2k of memory per request and the response is a
very small memory consumtion.
The advantage of using
the cloud-optimized framework is that we can include a copy of the mono CLR
with your website. For the sake of one website we do not need to upgrade the
.NET version on the entire machine. A different version of the CLR for a
different website running side by side.
MVC 6 is a part of
ASP.NET 5 that has been designed for cloud-optimized applications. The runtime
automatically picks the correct version of the library when our MVC application
is deployed to the cloud.
The Core CLR is also supposed to be tuned with a
high resource-efficient optimization.
Microsoft has made many MVC, Web API,
WebPage and SignalLr peices we call MVC 6.
Most of the problems are solved using the Roslyn
Compiler. In ASP.NET vNext uses the Roslyn Compiler. Using the Roslyn Compiler
we do not need to compile the application, it automatically compiles the
application code. You will edit a code file and can then see the changes by
refreshing the browser without stopping or rebuilding the project.
Run
on hosts other than IIS
Where we use MVC5 we can host it on an IIS server and we can also run it on top of an ASP. Net Pipeline, on the other hand MVC 6 has a feature that makes it better and that feature is itself hosted on an IIS server and a self-user pipeline.
Where we use MVC5 we can host it on an IIS server and we can also run it on top of an ASP. Net Pipeline, on the other hand MVC 6 has a feature that makes it better and that feature is itself hosted on an IIS server and a self-user pipeline.
Environment based configuration system
The configuration system provides an environment to easily deploy the application on the cloud. Our application works just like a configuration provider. It helps to retrieve the value from the various configuration sources like XML file.
MVC6 includes a new environment-based configuration system. Unlike something else it depends on just the Web.Config file in the previous version.
The configuration system provides an environment to easily deploy the application on the cloud. Our application works just like a configuration provider. It helps to retrieve the value from the various configuration sources like XML file.
MVC6 includes a new environment-based configuration system. Unlike something else it depends on just the Web.Config file in the previous version.
Dependency
injection
Using the IServiceProvider interface we can easily add our own dependency injection container. We can replace the default implementation with our own container.
Using the IServiceProvider interface we can easily add our own dependency injection container. We can replace the default implementation with our own container.
Supports
OWIN
We have complete control over the composable pipeline in MVC 6 applications. MVC 6 supports the OWIN abstraction.
We have complete control over the composable pipeline in MVC 6 applications. MVC 6 supports the OWIN abstraction.
Important components of an MVC6 application
The is a new file type in MVC6 as in the following:
The is a new file type in MVC6 as in the following:
The preceding files are new in MVC 6. Let's see what each of these files contain.
Config.Json
This file contains the application configuration in various places. We can define our application configuration, not just this file. There is no need to be concerned about how to connect to various sources to get the confutation value.
In the following code we add a connection string in the Config.json file.
This file contains the application configuration in various places. We can define our application configuration, not just this file. There is no need to be concerned about how to connect to various sources to get the confutation value.
In the following code we add a connection string in the Config.json file.
1. {
2. "Data": {
3. "DefaultConnection": {
4. "ConnectionString": "Server=server_name;Database=database_name;Trusted_Connection=True;MultipleActiveResultSets=true"
5. }
6. },
Project.json
This file contains the build information as well as
project dependencies. It can contain the commands used by the application.
1. {
2.
3. "webroot": "wwwroot",
4. "version": "1.0.0-*",
5. "dependencies": {
6. "Microsoft.AspNet.Mvc": "6.0.0-beta1",
7. "Microsoft.AspNet.Server.IIS": "1.0.0-alpha4",
8. },
9. "commands": {
10. /* Change the port number when you are self hosting this application */
11. "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
12.
13. },
14. "frameworks": {
15. "aspnet50": { },
16. "aspnetcore50": { }
17. },
18.
19. } }
Startup.cs
The Application Builder is used as a parameter when
the configure method is used when the Startup class is used by the host.
Global.json
Define the location for the project reference so that the projects can reference each other.
Define the location for the project reference so that the projects can reference each other.
Defining the Request Pipeline
If we look at the Startup.cs it contains a startup
method.
1. public Startup(IHostingEnvironment env)
2. {
3. // Setup configuration sources.
4. var Configuration = new Configuration();
5. Configuration.AddJsonFile("config.json");
6. Configuration .AddEnvironmentVariables();
7. }
Create
a Controller
If we look at the controller it is similar to the
controller in a MVC 5 application.
1. public class HomeController : Controller
2. {
3. public IActionResult Index()
4. {
5. return View();
6. }
The namespace for MVC6 is Microsoft.ASPNET.MVC
unlike the System.Web.MVC in the previous version. That is a big difference. In
MVC 6 the application does not need to be derived from the controller class. In
our controller there are many defaults functionalities. Most of the time we
might need to derive from the controller class, but if we do not need access to
all of the functionally provided by the controller class, we can define our
controller class.
1. public class HomeController : Controller
2. {
3. public ActionResult Index()
4. {
5. return View();
6. }
7. public string atul()
8. {
9. return "hello i am mvc6";
10.
11. }
If you execute the preceding method we may see
the following page.
No comments:
Post a Comment