Introduction to ASP.NET MVC
Microsoft Video Courses · 7 lessons · Free on YouTube
Introduction to ASP.NET MVC: 07 Introduction to Authentication
About this course
all right well welcome back it's good to see you and yes yes back in the saddle so for those of you who maybe missed us from earlier I am Christopher Harrison
John Delaware that's John Calloway good morning good afternoon good evening and wherever else it is that you might be it was very interesting on the chat before the call we got people staying it's the
middle of the night people in Malaysia all over the world I know it's really crazy that's always the fun part about this so but in the meantime this is introduction to asp.net MVC yeah what
we're gonna do is kind of introduce ourselves I'm apparently gonna bring up my Start menu there we go but we're gonna introduce ourselves we're going to kind of talk a little bit about well
what we're gonna talk about and then we're actually going to talk about it thank you for your game plastic Hey so with that John if you want to introduce yourself sure my name is John Galloway I
am I've been at Microsoft four and a half years now they haven't got rid of me yet I am a I'm gonna as your Technical Evangelist but I mostly focus on asp.net MVC yeah I just finished up
updates for the rocks nbc5 book so really excited about that so that's definitely something I spent a lot of time on and I have a podcast and I read happy to be here actually well that
works out well because I'm I'm kind of happy to be here as well as it says on the slide there I am Christopher Harrison I was an MC T for many many many moons presented at a good number of
conferences and read about Oh literally three weeks ago I actually got started here with the mothership as it were they offered me a position tonight just I couldn't refuse so I've been on
boarded as a Content developer for Microsoft learning experiences now as far as the the course itself goes this is basically going to be our next eight hours six hours a
which I guess will be the total time six hours probably recorded this is what we're gonna be covering so we're gonna start with the basics of MVC kind of talk about the different moving parts
what this is all about and then in modules two four and five dig into the EM dig into the sea and dig into the V and talk about each one of those different things talk about our models
talk about our controllers talk about our views in the middle there we'll go ahead and introduce visual studio and talk about all the cool things that visual studio can do for you because one
of the things that I find when people make the move into MVC especially if they're coming from web forms they look at that and they go oh my gosh that's a lot of code how about you know
drag-and-drop how about code generation so we'll talk about a lot of the different things that Visual Studio can I can do for you and then we're also gonna take a good look at both bootstrap
and identity identity of course came along with MVC v bootstrap was fully integrated with Visual Studio 2013 and I really kind of see how you can incorporate a little bit of additional
security and then get a very nice look and feel to to your sites and then finally since this is designed to be an intro course we're gonna take a look at sort of what your next steps are so if
this is your first real big experience taking a look at at MVC you're gonna leave here feeling okay well all that was cool and I learned an awful lot but you know where should I go from here and
so we're gonna talk about exactly that yeah at the end okay can we cut off heard of mine real quick I thought this was really interesting we we brought up a poll and we asked for different
people's experience level and so we got a we got let me see 18% beginning developer yep 10% experience with with HTML but new to net okay
12% we're experienced at net developers but new to web form so maybe back-end coders or desktop you know then 30% experience with web forms but new to MVC mmm-hmm 28% were some experience with
NBC but want to learn more and two percent were lion tamers well that's interesting lion tamers big audience yes I'm actually kind of surprised to see the number being being
that low right right yeah you know so I really thought we had that audience like that but but in any event the the real takeaway from all of that is the fact that we've got a lot of people out there
that are relatively new to two MVC and relatively new to kind of all of this which is very fantastic which bringing that into setting expectations is exactly what we're geared towards that
what we're really looking for is to try and connect with everybody who is relatively brand new so we expect that you maybe have a little bit of experience with with.net maybe you've
kind of real quick created an NBC project and when oh wow there's there's an awful lot of stuff here what in the world is going on and hopefully we'll be able to help clarify a lot of that and
then in particular talking to the webform developers that are taking a look at at NBC and maybe how that can actually assist them going forward in their in their different projects right
now as far as kind of if you want to follow along we will be talking about a github repository a little bit later we'll actually have that URL we'll share that out once we actually get some code
up there to share so that way if you're sitting at home sitting at the office and you're wanting access to our source code you'll be able to get to it pretty quickly pretty much like right after we
check it in you're gonna be able to go ahead and download that so we're actually very excited about that which by the way all of this is recorded live this is what's happening now it's
happening now so if something goes sideways with github remember we're going live so yeah exactly so here's our our right upfront apology something might go wrong no it was funny in the
last jumpstart yeah we had a lot we had people didn't believe us that it was well exactly and then we had to actually I forget we like put up the yeah yeah well we'll give soccer scores exactly
yeah or futbol Devon where you're from so in any event the other real quick thing to mention and John I don't know if you want to take two seconds and do this but if you are looking to follow
along or looking to maybe just get started the tool that you are gonna need of course is Visual Studio so yeah so can we well I think we're set up now we can
cut them there we go so if you go to Visual Studio calm and you click on free Visual Studio trial and you can actually well you if you logged in as me you can do that you know
there's also you can you can download if you you download a Visual Studio Express so visual studio express for web I think downloads here and underneath that we there's a Express and Express for web is
the one that you want yep Express 2013 for web completely free nobody'll ever you know it doesn't take any money from you you know you put it you register for it you download it
you're good to go and a cool new thing that we we just announced is that web essentials which is a nice extension for for Visual Studio is now also that's completely free and works with Express
as well that's awesome great out-of-the-box completely free get started with it no excuses and and if you haven't played around with web essentials you're gonna
be very impressed with it it's it's a neat neat neat little tool yep now let's talk a little bit about MBA and then we'll kind of launch on into it because I'm sure you're probably sitting there
thinking hey guys get to some code you'll see code but before we get into that just one last little thing here you are gonna notice that of course we do have my Virtual Academy over 1 million
registered users actually I believe that number is now 2 million I should it's being confirmed exactly millions and millions but anyway I say yeah so 2 million registered users which is pretty
incredible when you stop and think about it of course you can get points for attending this course you'll notice the little link to the voucher and then the voucher code is intro asp net MVC and
that's going to expire one month from it now so people want that voucher code because it's gonna get them those 50 points exactly that's exactly yet yep so what do you say we all launch on into
let's do it let's do it let's go ahead and talk about the the basics of MVC and the and the different moving parts oh okay great so let's cut over to mine I've got
the same slide showing so I'm not even sure how I'll know if it's going great okay so we're gonna talk first of all asp.net just the overview you know what what is a high-level what's there yeah
we'll look at kind of the what is the M and the V in the C in MVC and then finally we'll talk a little bit about what's the point yeah and that's that's the the biggest
thing I get that so frequently okay so asp.net in general that you may have seen a slide like this over time the idea is you've got this Common Core asp.net running under everything and
this is handling all your things like caching and security and you know actually serving responses out to users and things like that and then on top of that at the at the very top we've got
sites and services and the idea is that you know sites this is talking about you know delivering content to web browsers HTML it's forms people are interacting with it and then
services are things where you're sending you know XML or JSON or something other than HTML back and forth right and so then kind of the glue that you know the different parts that you can
use to hook those together mm-hm our MVC is kind of one of these things in the middle and it's designed for serving up websites right and I think the real point of this here is that it's all the
same kind of family yes so the idea is if you're familiar with web forms this isn't something brand new completely different all asp.net under the hood right and the idea now is that you're
just kind of it's it's a new it's a different coding model but it's running on top of all the same things you're already familiar with so a lot of if you are making that move from web forms then
a lot of what you've already learned is going to be transferable then into into MVC that it is still one asp.net to rule them all right as it were and and that's gotten even better with the the latest
release Visual Studio 2013 yes we've made a you know real effort that when it probably the biggest web dev feature in Visual Studio 2013 was the idea that it's one asp.net so it's very easy now
to say you know I'm going to in one project have NBC and web forms and signal art and web api I'll pick and choose what I'd like exactly and probably you know that's
nice to know you could do that what's even better is to know that even if you've got one like let's say you're working completely in NBC yep for a week and then you jump over to web forms
identity you know the scaffolding the bootstrap system all that's the same across them so you can take your skills and jump between them pretty easily and that's a big thing yep yep cool okay so
that's kind of where we are looking at with NBC now let's talk about specifically what is NBC so every NBC presentation has to start with some kind of yep and I used to always see these
you know there would be a box with an M and a box with an M or V and a box with a C and arrows going between them I never really followed what was going on so this is my version of that
the idea is yep looking at specifically what happens when somebody requests somebody typed something into their browser right so a request comes in that gets routed to a controller now this is
a big this is you know first kind of big difference between something like web forms or PHP or write some of these kind of more file based systems classic ASP yep right
ColdFusion and so in those requests a URL maps to a file right and then file does something and then returns a response right in this case it's completely different right the request
comes into a method of a class exactly yeah the simplest way that I always like to explain that is that really what's happening is the user is calling a method on a class that really is it so
I'm like in the past like John mentioned you're not going to a PHP file you're not going to an aspx file you're calling a method on a class now there's a little bit of magic that'll happen we'll talk a
little bit about that later on how asp.net will figure out what method it is that needs to be called but at the end of the day that's what it is so your controllers are class and you're going
to be calling a method and and by the way this is always my favorite part is I love that right on there the the controller retrieves the model and does stuff yep
and really I mean because it's completely open that controller could be could be authenticating someone it could be you know anything it could be doing a database lookup it could be putting
something in a database it could be creating an image whatever it is it does something yeah bad stuff so this is a key thing to you know it's a key difference it's also kind of freeing
because when when I was working with web forms a lot it was always kind of like well the URL comes to a file and that file needs to decide here it's like it's a method and that method can make
decisions run logic yeah it like wait yeah that said and it makes it so much easier in trying to group things together rather than trying to figure out okay well what am I gonna call this
page and what am I gonna call this page and and you know what's my folder structure are gonna look like and so forth now it's all about just good class design mm-hmm great yeah okay so we've
done some stuff in the controller a lot of the time the result of doing something is data you know we process somebody comes to requests a controller action that says get me a list of users
we're gonna be playing with this MVC music store sample and so you know maybe get me a list of albums right or artists and so then that that result is the model so a model is just packaging up
some data to ship off to present to the user yep so and and we'll be talking about this more later but this is just a class exactly it's just a here's some stuff
and we're packaging it together to send somewhere else the one thing I and if I can jump in for two seconds here only because somebody had asked the question in the in the chat window about view
models they asked you notice the controller liked the view model if we go back to the slide here real quick what you're gonna notice there is that is that model that model could be what's
known as a view model which is a class just like John mentioned but this time specifically geared for MVC so it's not going to have any logic about how its connecting out to a database or to web
service that it is just hey this is the data that we want the user to to interact with and that's a really key point great question so that yeah absolutely
so the idea here the model is not directly hooked up to your database the model not there's no the model could just be a collection it could be an array it could
be a can actually just be a simple data it can be a string yep so it's just something that the controller is passing to the view so then the view is what represents that data so we've got you
know a controller action did something it created some data and now we actually want to return we want to show something on the user screen right and so that the views job is to take that data to take
that model information and turn it into HTML mm-hm and that's all it does so the important really important thing here is there's they call it separation of concerns so the idea is that the
controller has no idea about how to display HTML it doesn't even know it's displaying HTML it could be displaying some other exactly type or whatever yeah it could be returning Jason yeah
actually yep so and then the model is just some data it's it really doesn't have any logic right you can put validation logic in them and stuff but generally models don't know where they
came from and they don't know where they're going yep and then the view is the is it has no logic really in it you want abused to just have HTML and just say here's my model information it's a
template system exactly yeah that one big thing that I always like to kind of mention is if you're putting an if statement into your view and we'll talk a little bit about coding into your
views and so forth but I was like say if you're putting an if statement into your view you might be doing the wrong thing that it's a code smell to quote Martin Fowler from the from the book
refactoring it's a code smell it's it's not necessarily a 100 percent indication that hey you've done something bad but it's one of those where it could indicate yeah after you exactly exactly
that just like you mentioned before with a view we really want that to just display the data so let the controller do the logic let the controller forget about oh hey wait we need to display an
item not found' page as opposed to putting that logic inside that view which bringing it all the way back to those moving parts you'll notice that separation of concern so the controller
takes the request it does stuff it's and get the data that the user is going to need that data is going to be inside the model the model is combined with the view the view handles the display and
then out the door it goes great yep and so that's the last thing on my slide here is the out the door it goes right yep so so that's the technical way to do right and where it goes let me see if I
can do this if I do it maybe say a laser pointer is that gonna work yeah so okay so with hi-tech here so right so we've got this whole kind of flow the request comes in goes to the controller
controller runs the logic the packages creates the view the templating system turns that model data into into HTML and comes and the outcomes the response so the question is where is all the code
and you know the view like you said the view is really supposed to be lightweight just make HTML exactly yep the model just holds data so then my natural conclusion when I started doing
this is like well of course all that all my code goes in my controller right so just like I used to do with web forms I'm going to throw all my code in my controller and and you're you'll learn
very soon we'll talk about some best practices that's not where you want to do it either right so so an important thing that I want to point out is this is not your whole application no this is
the flow of NBC and then good coding patterns say that your controller is gonna call off to some services exactly have some data access classes you're gonna have all these other things so
this is this is the request response part and then you build out your application on top of that right exactly great yeah ok so that's my big diagram I think we're getting ok so now let's
talk about why yeah exactly we've got all of this going on we've got all these different moving parts you know web forms it was it was simple I just drag and I drop in a way I go why why why did
we have to do this why do you have to change all this right exactly yeah so um you know web forms or like WordPress or whatever right you know why can't I just drop in a plugin or something so so um
here are some some reasons I came up with and these are things that I you know having done web forms and classic ASP and a little PHP before doing before starting on MVC
these are some advantages that I found when I started working with mu C so one is it's very easy to as you start building it's very easy to drag and drop something and get started right six
months later or a year later you've got a big mess right and and so you really need some structure in your application right yep and the ways that we've done this in places I've worked is you know
maybe the architects wrote up this huge standards document you know and said all data access needs to go through our DLL and we'll present you know or people said you need to have a separate project
for your business logic and a separate project for this and yeah you know or you know any other type of web dev platform the same sort of thing you end up running on some framework cake PHP or
whatever it is you know yeah or you end up you know building up okay all my stuff here goes over in this folder and stuff but it takes some work to build some structure NBC gives you that
structure right from the beginning exactly so that that's you know I guess point one and point two are really the same thing yeah you start is start to finish you've got kind of a basic
structure right that that MVC lends itself so much better to a well structured application than web forms does you know that with web forms it just becomes so easy just to drag out a
button double-click on it and then write three pages of code and it's not to say that you can't write bad code in MVC you absolutely can but it lends itself that much better to writing good code
yep and you know as we're comparing and contrasting we're really doing it from the point of view of setting you know explaining why what's the point of MVC yep as you said you can write bad code
in MVC you can also write fabulous amazing code and in Webb facility right the other thing in the other framework as well right so our point is not to bash on other things it's really to kind
of say explain why MVC works the way it does right yep so with MVC you know you often will find that you've got more classes and more methods but tiny bits of code in them and so like for instance
your controller actions will often have two or three lines of code because they're just calling off to a calm servus yep so so you end up by breaking things apart you actually end up with
less code because you've got less conditional logic unless you know all this kind of mapping things back and forth all that sort of stuff yeah and then finally you have kind of a very
smooth learning curve so what I found and I'll get with web forms again it's very easy to do file new project start setting things up you know set up my master page start dragging grid views in
start you know hooking up data as things get more difficult then I run into some tough challenges where it's like how do these two controls work together or I need some abstraction here because you
know my data needs to do something before it hits this or you know this control just doesn't do it I need to do now I need to write my own server control that's hard yeah exactly or you
know I need to dig into membership and that you know like how does that interact with my controls so the idea is that there is more work in starting with MVC mly right there's a little bit of
ramp up the point is that it's worth it yep okay Trust doesn't worth it and like I I had a great opportunity and you almost never get this opportunity to write the same application in two
different frameworks writing okay I had this was for a person Microsoft conferences before I joined Microsoft we built some conference websites we built one in web forms worked great
you know it's highly scalable and then we felt we needed to do some updates and there were some internal changes that were big enough on how we're getting data and things we said we're gonna redo
this using MVC and it was really interesting to see the places where things like being able to control our urls being able to centralize our data access and and just we ended up the
getting started took a little more thought with NBC but the end of the project was smooth whereas with web forms we ended up the end of the project was oh shoot how are we going to make
this work right that's kind of a you know that smooth ramp human and that is one of those things that I found personally as well is anytime that changes were needed it's always so much
easier to go into MVC and update all of that that it is in in web forms yep because after all the only constant in software development is changed right
right so just a few a few more things specifically on web forms so some of the values that you've got in web forms is the idea of you know you are it's very quick to get going you're using controls
that create your HTML Javascript and CSS and so you're not directly writing that you can but you're not directly writing you're responsible for that HTML Javascript and CSS so the controls are
doing that for you and the controls often are handling browser differences as well not as important now that browser standards have really kind of kicked in but previously the the
controls we're doing a lot of right you know is this an down level browser it's this sort of browser and the up kind of thing so web forms handles a lot of things for you here's the problem with
that in order to handle all those things for you I don't know if you've seen if you're an experienced web forms dev you've probably seen this this diagram or something like it you're not going to
be able to read it on this slide that's not the point the point is there's all the way we can't redo this yeah so the fact that you can't read it don't worry about that
that's really not the point the point is that there's this life cycle there's this thing okay we're going to you know pre page this pre render view state pre whatever it is and we have to load up
the we have to load up the state of what everything's in understand what all the control state is exactly do some processing and each control has to jump in and there turn it cetera yep so
here's the problem with that we you know you've got your one page that has your default you know the that's running all these events and that's just one page that's that's one one paid but even in
that one page there's actually three different sets of events going on because you've got your master page mm-hmm and and that's handling all your common site layout and then you've got
your page itself and that page is running user controls as well yep right so this is getting a little more complex but so so just to kind of sum all that out that's one page we've got products
aspx but yet there's three sets of life cycles there because there's one for the master to set up all the structure there's one for the page itself and then if you have
a user control on top of all of that you've got that so you've got all of those different events that you have to potentially go in and capture and not to sort of give something away but there's
also the matter of trying to name all the different controls we'll get to that in a second yeah but yeah there's so many different moving parts here right for one day and this is one page and
then again your site has multiple pages probably I'm just gonna guess that your site has more than one page in it yeah so that's that's one issue that you can run into the that makes things more
complex another thing is that in web forms this is a view state our friend view state and the reason to show this here you can the way that these controls work is their their handling state for
you their remembering what happened between you know I load something up I fill something out on a form I populate a grid I send it back to the user the user sends it we send the information
back and forth yep and those controls are making it seem as if that state was persistent exactly even though the web is not persistent at all it's right every time you talk to a server so who
are you again right one of the things I always like to say is that there's no magic in fill in the blank so there's no magic in web forms the fact that you're able to drag and drop that control and
poof hey look it's displaying data there's still a lot of work that's being done behind the scenes even though you're not necessarily seeing the code nor writing the code there's still a lot
that's that's being done to make all of that happen right and then one last thing and I'm really not trying to beat a dead horse because because I'm a fan of web forms but I I want to point out
these are just some things if you're very familiar with web forms this is another thing that that can be an issue is since it's generating your HTML for you you don't have controls you don't
have as direct control over the IDs and classes now all of these things are fixable on web forms if you're an experienced web forms dev you're gritting your teeth because you're
saying wait a minute I can control view state their switches there's a very specific controls over this there are very specific controls over I can change my HTML markup
and I can you know I can well handling the events that's something that I've you know kind of learned I've got my own structure etc it's true but these are all these are all the things
that you have to solve these are problems you need to solve in some different you know they're they're things that you need to go in and do specifically so these are all things
that MVC was designed to handle for you know to handle differently right get rid of these problems right one other really important thing with NBC is that it's designed for testability so the idea is
unit testing is a it's just the practice of testing your code in code right right and and the point is when you go in and make a change it's easy to write some code and make new work and then you say
I'm done woohoo right that code lives on and later someone might need to fix a bug you know or change some functionality and then what happens right and so the whole idea is that you
I think of unit tests as a safety net they are a seatbelt a seatbelt exact so the idea is I would like to go in and change some code that maybe I wrote a month ago or a year ago somebody you
wrote it who knows who wrote I I want to go in and change this code and I want to make sure that I didn't break everything yeah that's all a unit test is that's it so it's a few lines of code that verify
behavior they verify that what comes in does some things what's the expected result and and let's sort of compare and contrast how that's done quite typically with developers that maybe haven't done
unit testing in the past is you sit down you create something you go oh I want to confirm that this works well what are you going to do you're then going to write just enough code to like test it
inside of a page so you'll go in you'll create the view let's say and then you're getting a fire up in your browser you'll throw a couple of silly little values at it you'll see oh look I got an
error message or oh look I got the value that I was expecting and then you delete that and then you move on and that's not it not only is that a not overly effective but be it just as john
mentioned it's not going to live on so when it does come time to make a change or it does come time to fix a bug how are you going to know that what you actually did works unless you
go back to that process again and again and again with unit testing test driven development all of that is automated so if you're not already doing it it's absolutely something that you need to
consider doing and don't underestimate the the power of unit testing of test-driven development yeah and you know this is something where you know my first introduction to testing was we had
a big QA department and we would work on something for a while and then QA would start testing it and they would find a bunch of bugs and then we would you know finally resolve enough of their bugs
that they were happy with it they'd sign off and then we'd ship the feature and then we'd add new features in but did those features break some other features across on some other part of the
application maybe QA is going to catch it maybe they're not right and so the problem is that software is very interconnected and changing one place may have a lot of
effects that we're not thinking of and unit tests live on as you're saying and so I can run my unit test suite later and boom everything's good exactly not – and and this all I I guess
sort of be the last little thing otherwise we could we go urban development first of the day but in any event the one last little thing that's worth mentioning is that when you do go
in and create those unit tests because they do live on you want them to be production level code you want them to be artifacts that is something that you are going to generate so that way you
can when you go to make those changes go back to those unit tests and that's a quick way to see hey look I made a change over here in theory that shouldn't be related to anything that
I'm doing over here but you know how many times does this happen even though in theory they shouldn't be related all of a sudden you find out that something happened and now that they are with unit
tests it's very easy for me to pick that up mm-hmm so as Christopher said unfortunately we're not able to with this as an introduction to MVC and we're focusing
specifically on developing and be secretive I'm not sure if we have MPA courses on unit testing but that would be a very interesting course if not there is a lot of good information also
on asp.net site and on MSDN yep on unit testing yeah so but the point is that NBC is designed so that it's not hard to unit test exactly because everything is written it's very
separated out because a controller you know has specific input and output and it doesn't create HTML and it doesn't interact with you know the browser directly and and the view you know we
can go in and we can test everything exact isolations yeah exactly yeah and we'll continue to dig into that as as we go forward great yeah okay I think it's time for some actual
yeah let's actually do something you know we've been talking it awful right exactly so but the point is you know we want to kind of set the beginnings we want to talk about what we're talking
about right yeah yeah absolutely although that was important I found it interesting I hope everybody else I think it's good stuff all right so here let me if I'm not doing this I'm gonna
end my slideshow I'm gonna switch over to visual studio are we on my desktop okay yeah remember you have to escape out of the slide all right Cirque it's it's been a little while since we've
done this yeah so back to PowerPoint yeah and escape out escape Oh yep please can buy so in the meantime the where's my the whole goal of all of this is really to make this again more code
focus and whenever I'm talking to web form developers one of the things that I find is that they do sort of look sideways at me like hey why don't we want to make this code focused why not
keep just using the drag-and-drop while you're not keep using that WYSIWYG but by making a code focused again it allows you to have that good separation of concern it allows you to really kind of
better scale this better handle changes and then also it does help make it testable that one of the big things we'll be highlighting a little bit later is that at the end of the day all their
model is is it to class and all that controller is is it's a class and classes are always testable so that's that that is gonna make your life in the long run that much easier yeah all right
I do believe we've got a desktop now we do have a deck sides and thank you for hanging in with us this is the morning we're all getting started computers are getting out there coffee we're getting
our coffee we're all good though okay so I'm going to to create a new web application yes so actually so I'm gonna go file new project and I would like to create web
up makes it obviously go with yeah yeah I'm gonna do it you want to be coding in C sharp today that is good to know if you are a VB developer all this stuff works you can go you know web and you
can code away in Visual Basic as well yeah so here I'm creating a new web application here's an important thing if you are go ahead oh no I was gonna let ya I don't want to steal your head go
for it well if you weren't gonna mention it I was gonna mention ya if you've been coding in asp.net before we used to give you a lot of choices yeah add new web application yep so you have to say well
am I going to create MVC or web forms today right and what we've done now with with 2013 is this is one asp.net yep so we're going to create an asp.net application exactly and one of the
things while while John in the background here is typing in his little project name and he's gonna hit OK here in just a second one of the big things that I want to highlight because this
goes to a question we got asked in the chat window is hey is it possible to have balled MVC and web forms inside the exact same project well there's your answer to that question you'll notice
right down towards the very bottom that you've got check boxes so right there you've got web forms and Web API so that way you can just simply choose oh yes I am gonna need this or I am gonna need
this which in particular if you are making the move from web forms into MVC and you're going well we've got a lot of existing code we don't necessarily want to go back and rewrite it but we want to
do some new stuff in MVC there you go yeah I think I stole your thunder then oh well no this is great so the idea if that's exactly that's exactly and I'm glad someone asks the question you know
yes so the point is now you have these choices instead so I picture this in my head is the difference between options and choices sometimes a choice can force you into something right I like to have
options absolutely so for instance going to dinner last night we went to dinner and we got hamburgers yep and that was great but
I don't want to have to say you know what do you want to eat for dinner for the rest of your life no because I might not want a hamburger every single night maybe some spaghetti it's maybe some
spaghetti from there we go a little bit of an Easter Egg for those who are exactly so but so I would like to be able to say well I would like to start with NBC but sometimes I'm gonna be
using some web forms and sometimes I'll also be using some web API right so the idea here is you know I can say I would like an empty project but throw in some web API and some web forms for me yep or
I would like you know web forums but I also want support for NBC what's also nice is after I've made these choices let's say I'm start out and I say now I'm good with just web forms and a month
later I say I want to use some NBC you can also when you bring in scaffolding in here it'll automatically pull in the NBC stuff for absolutely I don't interrupt you for two seconds only
because we got a great question yes please hey can we use say for example the same authentication mechanism for MBC and for web forms in that same project and the answer to that question
is yes yes because at the end of the day it's all asp.net right so excellent so if we here is the same you know new project page so here if I say change authentication and we're gonna be
looking at this in our and our last second to last session today but this is the exact same dialogue here setting up different authentication accounts and all that exact same thing whether you
click this or this yep and what's nice is it's several things one is your skills transfer across so you're really good with asp.net identity and MVC and then you go to help your friend on a web
forms project it all moves across well also if I have one application and I've got mostly web forms but a few MVC controllers in there no problem they all speak the same language exactly so so
that's great so I'm going to click an MVC application hold on one second only because I do me a favor zoom in on that bottom right corner yep you took the check away real quick but
this is something that that we really should highlight yeah that Windows Azure that host in the cloud one of the things unfortunately that we're not gonna have time for we're trying to make this an
intro course so you really do wind up having to pick and choose the different things that that you demo and unfortunately we're not going to have the opportunity to demo deployment today
but since we've got the screen here it's still worth highlighting real quickly is you'll notice the integration now with Azure and visual studio that all that you would have to do is just put a
little check next to hosts in the cloud when you hit OK it will then ask you hey do you want to go ahead and use an existing website do you want to create a brand new one how about your database
and do all of that right through visual studio and then that way rather than having to go to the browser create the website download the publish file you can do that just by putting a check
right there which is wonderful yep in one place this really is helpful is a lot of the time if you're starting a project and you're working on a team two or three developers or maybe a big group
one of the first things you'll need to do is set up a database right yep and so then you know part of your first day is setting up the project creating the database and getting everyone set up on
it one nice thing here is by checking the box yep everyone on my team that's working on this project automatically can connect to that database it's already provisioned up on the cloud I
don't have to go to IT and say please spin up a database for me exactly because it's already and this is a local it's a database that's you know it's hosted for me yep and if you've got MSDN
benefits especially you've got free free sequel and as well anybody when you create a new website an azure website yep that includes a 20 megabyte I believe sequel database for free for
free yeah exactly it's great for you know getting started and sample data and all that and there is also a free website as well that if you're just looking to do kind of basic stuff it's a
great way to go ahead and start integrating the the cloud today with essentially no money down exactly so one other thing I'm going to do and we're not going to dig into it more but
I want to check this ad unit test box and I'm recommending in general just check this box it'll set you so that it's not hard to write a unit test because part of the thing with unit
testing is if you have one test that's a heck of a lot better than no tests right right and so you don't have to you by checking by you know getting started and putting in a few net unit tests maybe if
a big you know difficult bug report comes in and you solve this write a unit test that verifies that that bug is fixed yeah and it's it's great so just checking this box makes it easier to
just kind of get started down that path exactly so it's not your it's not a big deal just check the box and you kind of get started in the right direction right so I want to point out one thing that's
going on here and that is as this application is spinning up that spot went by pretty quickly but I was I'm pointing out in the taskbar there that it is adding a bunch of nougat packages
right so in the past when we created a new project it was actually just unzipping some files of them that you had locally now it's installing a bunch of new get packages and nougat is a
package management system for dotnet right and what that does is it allows for you know easily breaking things apart putting things together adding new capabilities to your application exactly
handling dependency is all that kind of and the biggest thing that nougat does because a lot of times people look at nougat and go well why not just simply create references to dll's well two
things that nougat can do for you number one is go beyond dll's that it can set up JavaScript files and CSS files and the other things that you're going to need but also number two is that nougat
just like John mentioned can detect dependencies that it can go oh wait a minute you're wanting to install this package this package depends on this and this
let me automatically go ahead and grab those for you making sure that you've got everything that you need and then right there on the slide John is is highlighting a whole bunch of the
different nougat packages that are that are out there yeah so what I wanted to do here is just to point out what you're saying these are the nougat packages that are installed in your application
as an example jQuery is not a dll it's it's JavaScript but jQuery validation depends on the jQuery live exactly yum so what that's going to do is it's going to say okay
when because you've got the jQuery validation I'm going to make sure that you've got jQuery installed and the right versions right where that and you'll notice support for MVC is brought
in as a new get package yep so the point is if you've got a web forms application you can bring in MVC into your hmm into your web forms project and it's it's actually just installing a new get
package for you one of the things I wanted to do point is point out first of all getting started this is your when you do file new project this is a really handy page
to know about so this is this tells you a lot of kind of what to do next stuff so this is actually very useful and I recommend file new project and click through this and it's a good start it is
a good start because one of the things unfortunately in the past it's not a lot of times that Start screen came up and we all just sort of got into the habit of ignoring it because there wasn't
necessarily a lot of great information on there that's changed there really is a lot of wonderful information that's on this screen and I'm the deploy like the the ensure your app is ready for
production make sure that you read through that that there's a lot of little things that people frequently miss yep all right so let's take a look at what actually was created in our app
here yep so an important thing to getting started is understanding the directory structure right so we have a we're talking to MVC today we have models you have views and we have
controllers Wow Wow okay all right I'm still with you yeah I am actually trying to get it renamed because we've also got scripts and content and Cesc I'm working on it but the point is this is we're
talking earlier about one of the advantages of MVC is kind of giving you some structure off the bat right this is that structure right so if we're if we're looking at you know where is a
controller where if maybe we're working on an application together and and you say hey fix something in the home controller well I know where that's going to be right okay we talked about
controllers are just classes and with methods in them methods will dig into all this and much more detail later we're just kind of showing you around right right yeah just
give me the the nickel tour is aware so here is a controller right which is a class it's a clam Lotus public class home controller now it inherits from controller but it's a class yeah that's
it it's a class and that that controller just kind of makes it easier to do like it it includes some some behaviors for you and stuff it really it stays out of your way for the most part you have a
class and then you create methods on it and this is an action method so when somebody calls into a controller this action method is actually what's going to spin up yep then models is where we
will put our models and what we've got a whole class about the this later there are actually some at the very beginning of as you create your application because you're your user identity is
actually stored using this whole kind of system and rightly this is a model yep and so that is your your identity model there and then finally your views and it's important to understand there's
these conventions that map where things go so I am in the home controller and I go to the index method and I say return view well which view right and this is where conventions kick in and say if I
am on the home controller and I'm looking for the index methods view then let's find that let's just kind of look around well if we go and view this there's a home directory that matches to
the home controller and there is an index view and so just because of those names match that's how it finds it yep so and and we're short on time here so we're not really gonna dig into this in
detail but I just want to actually you know if I say this is my home view and I say you know intro to MVC on MVA right yeah I've edited the title and then I say MVC is fun right
so here I've edited some HTML re excavation absolutely that's a lot of fun right so and the controller so when I browse to the site the home
controller is the thing that spins up it's going to say return view yep and that view is going to return the index so let's just run that you got actually like if I'm going to create a project we
actually need to see something on this absolutely and I think at that point then after we see this loop in up with our glorious new page showing us how much fun NBC is I think we're ready to
take a break do me one real quick video just since it's on your screen do me a favor maximize that browser real quick for me yep there we go and what I want to highlight on John's screen real quick
is you'll notice now down towards the bottom is three columns go ahead and and and restore your screen again to there we go and now you'll notice when he goes in and resizes his browser now it's down
to one column one of the big questions that has come up a couple of times in the chat window has been about setting up for mobile this is a little thing called bootstrap or actually gonna have
a full module on snap which I'm very excited about but one of the big goals of bootstrap is doing this type of dynamic resizing and this isn't to say that you're not necessarily still gonna
need to go in and create views for specific device types you still very well might write this does eliminate a lot of that need however that this will automatically scale based on the device
type so it makes it that much easier to program for for mobile devices yeah and this is great because this is all done using CSS it is exactly it isn't on the server there's no code to detect that a
writable browser yep there's no JavaScript code this is all just done using CSS so it's not going to break when some new phone comes out that it doesn't know about etcetera it's all
done just based on how wide the screen is yep so okay so let's talk about what we've covered here we've done you know we've talked about what MVC is yep we've talked about why you should care yep and
then we've done just the very quick file new project what's involved in creating a new project yep and we've looked at you know controllers where the controllers go yep we've looked at a
controller returning of you and actually an important thing to notice there is this controller didn't have any model data – right under the view nope so in this case the model wasn't there
right it just simply displayed a page so that is the very very simple case it does okay yeah so so we'll take a 10-minute break and then we'll be coming back and we'll be talking specifically
about controllers and more detail and and and we'll have I have a burger yay all right all right I'm going to enjoy this delicious burger if they'll bring it back for me and have a great break
we'll see untested we'll see in ten
THERE IS ALWAYS MORE