What's new in .NET 8 ? Dotnet 8 new features #build2023 #dotnet8

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
um welcome oh wow it's great to be here back at Microsoft build with all of you um I'm Daniel Roth and I'm here with my colleague Jeremy lickness hello everyone we're both product managers on the asp.net team at Microsoft and we're excited to share with you today all the great new features coming for web developers in.net H for front ends back ends and futures dot net is a complete solution for building modern web applications with net you don't need to piece together a solution from multiple different Frameworks whether you're building a beautiful web UI or a native client with powerful back-end Services accessing data.net pretty much has everything you need right out of the box.net is built for security it's optimized for performance so that you're ready to handle any workload now some of the largest services and apps in the world are built on the trusted.net platform and as.net gets better with every release those services and apps just reap the benefits for example Microsoft teams they recently upgraded their permission service to.net6 this is a service that handles 60 000 requests per second when they upgrade it to net six they saw 30 percent better input latency 45 better outgoing latency and they doubled their server efficiency Microsoft Bing recently upgraded their high performance workflow engine called zap to.net 7. this is an engine that handles running 900 000 instances executing 30 000 nodes per second on each machine they improve their startup Time by forty percent and P95 latency by up to seven percent the improvements were so dramatic that they actually came to us and said you know initially we thought something was broken we thought we had broken something but we investigated and looked and no these these performance improvements were all 100 percent real with net you can build an entire web application from the front end to the back end it's a full stack web framework now on the front end many applications need to use a variety of approaches in order to deliver the best web UI experience for example maybe some pages are best handled from the server in response to requests so they load almost instantly and they're easily indexed this is called server side rendering and Dot net has great support for server-side rendering with Frameworks like MVC and razor pages in other cases it might be best to handle that UI from the client using client-side rendering so you get rich interactivity and you have access to client capabilities with Donette you can build client web UI using Blazer now many apps actually need to use a combination of these two approaches to deliver the best web UI experience to to their users in dot net a we're combining the strengths of server and client-side rendering with Blazer's convenient component model so that you can deliver full stack web UI using a single framework this is the best of client and server let me show you what I mean okay so this application this is a recipe application and it's built entirely using Blazer on the home page you can see that we can we have a bunch of recipes and then in if we click on one of these recipes we can see that the let me just refresh this page real quick we can see that we can see some details about the the recipes now if we go back to the home page let's take a look at the what this app looks like in the browser Dev tools now if I refresh the home page now this is a Blazer app but if we filter for just webassembly there's no web assembly being downloaded for this app there's no websocket connections being set up to run this app there's not even any JavaScript being downloaded this app is being entirely rendered from the server using server side rendering in dotted 8 you can do full server-side rendering with blazer now let me show you what that looks like in the code if we go to the project for this application let's bring up the components for the home page and for the recipe Details page now each of these pages is actually a Blazer component that's set up as a routable endpoint on the server so as a request comes into the server the request is routed to the corresponding Blazer component and it renders a full HTML response in response to that request so full server-side rendering with blazer now we can do form handling as well let's go back to the app and I'm just going to search for let's search for all the chocolate recipes this is that was a form request right there I did a get request so we can see all the chocolate recipes let's pick one and at the bottom there's another Forum here for submitting recipe reviews let's give this one a five star review says super yummy and we'll submit that and if we scroll back down we can see the rest the review was added if we submit this form without any data we also get form validation working as well now how is that implemented let's go back to the app this is the recipe details component if we scroll down a bit we can find that star rating reviews component let's right click and go to definition and here we can see that we're using the built-in Blazer edit form and input components to render that form these components will bind the request data they'll validate that data before then calling your on submit Handler all from the server so we do full server-side rendering with blazer now because we're doing that rendering with laser we can now start to enhance the user experience of this app for example let's look at navigation like when I click on a recipe or go back that's doing a full page page load right now that's why you might see like a brief UI blip as you navigate also if I go to a recipe and I submit one of those reviews again you may have seen this before may have noticed that if I submit that review I'm actually losing the scroll position on the page as the the page loads we can enhance that user experience by adding a little bit of client-side logic let's go back to our code and let's go find the layout for the application here in mainlayout.razer and if we scroll down to the bottom I'm just going to uncomment the Blazer script and we'll go ahead and apply that to the running application wait for that to apply there it goes okay so now if I go back to the homepage and if I start clicking around you may notice it's very subtle but the the UI blip is gone the navigations are now fast and silky smooth similarly if I go back to that form and let's submit another review let's I don't know what do we do the fifth one awesome make sure I can spell and submit that ah so the review got added but I no longer lost the scroll position how is that working well Blazer is now intercepting the request like for a navigation request and the rendering is still happening from the server but Blazer is then intercepting the return to HTML content and applying it to the Dom without having to do a full page load same thing for our enhanced forms it's intercepting the request and handling the HTML response and updating the Dom seamlessly so our app starts to feel like almost like a single page app like a spa but it's still doing full server-side rendering now some pages need to do long-running async tasks in order to to render like for example on this recipe page maybe we need to do a database query to get all these recipes or make an API call that can delay the rendering of the page because you typically have to wait for all those tasks to complete before you can fully render the page let me show you what I mean like if I go back to the code let's let's add a it'll be a simulated simulated database call to our recipe app so here's where we're getting the recipes and right here I'm just going to uncomment this task dot delay as if we're making a database call that's taking a full second we'll go ahead and apply that to the to the app all right great so if we go back to the application and now if I refresh the page ready click there's one 1000 Boop and then it finished rendering it's a little easier to see if I navigate to a different page and then back ready click one 1000 then it renders we're having to wait for that simulated database query to complete before the page renders we can improve that user experience in dot net 8. using streaming rendering streaming rendering will allow the page to render immediately with placeholder content while those long-running async tasks are executing and then when they complete the component is rendered again and Blazer handles well streaming the the new content on the same response connection and then applying it to the to the Dom let me show you how easy that is to enable we'll just go to our home page let's go back to index.razer and I'm going to uncom uncomment this attribute to enable streaming rendering streaming rendering true we'll go ahead and restart the app now take a note here in in this page we have a little bit of logic that if we don't have the recipes yet so when the page initially renders we can render just a placeholder content you know loading recipes dot dot dot well that database query is executing and then later once the database query is completed this page will render again and we'll render all the recipes and then Blazer will stream that down to the client and it should get seamlessly updated okay so as soon as it's done building and restart we'll see that in action let's see where the build there it goes okay so we've rebuilt I'm just gonna wait for the browser to pop up so we'll see streaming rendering coming down to the client you gotta use the trick Dan everything up okay you may have seen it it was really quick I'm going to refresh again ready to refresh you see loading recipes dot dot dot and then the recipes come in the page loads instantly with the placeholder content and then the stream content comes in later still rendering from the server but now we get a much more responsive user experience pixels on the screen as fast as possible and then updated seamlessly so that's streaming rendering with blazer in.net8 okay so far everything we've been doing with this app is still rendering from the server but now I want to add some like Rich interactivity to this application there's another page in this app which is the submit recipe page and it has this recipe editor and I want this to be a more uh sophisticated UI like for example I want to be able to upload a picture let's pick one of these salads and instead of just displaying the file name I'd like to be able to see a full preview of that picture also we have this ingredients list editor where I should be able to add ingredients and edit them and reorder them with us like drag and drop but if I click the ad button right now doesn't do anything yet that's because this page is still using server side rendering it's not interactive yet let's make it interactive we'll go back to the code and we'll go find the submit recipe page which is right here and we're going to apply a render mode to this page and we're going to start out using render mode server as in Blazer server that means all of the UI interactions for this page are going to be handled over a Blazer server-based websocket connection hopefully that should make this page now have a nice interactive experience Okay so we've restarted the app let's go back to submit recipes and now let's try and upload a picture let's pick the pancake one this time there we go all the our client logic is kicking in our interactive logic we can now add some ingredients like maybe let's add some flour and a couple of eggs and I don't know a few Ducks why not we can switch between metric and imperial units we can drag and drop we now have a nice interactive UI within what is still otherwise a server-side rendered app that's this is really cool like if I go back to the home page and let's now go back to the browser Dev tools let's remove all of our filters and refresh this page okay so on the home page do we have any websocket connections being established yet I'm filtering for websockets nothing yet but if I browse now to submit recipe aha so now we see the Blazer server websocket connection is being established just for this page and then if I leave this page that connection can be freed up along with all of its server resources so it's much more efficient a little island of Blazer server interactivity in this app now we can use Blazer webassembly too let's go back to the app and switch this render mode from server to a web assembly we could do that we'll go ahead and restart the app now one thing you may notice is that this app and it's this is actually building out of the full asp.net core repo so it's a big solution but the project is actually just a single project we don't need a separate project to build for Blazer web assembly and that's thanks to multi-targeting the same project is being built for both the server and the client so we get a single project Dev experience okay so let's see what this looks like now in the browser let's bring up the browser Dev tools and oop no not that let me go back to the network tab remove all our filters I'm going to also clear out all the site data for this app just to make sure we don't have any Blazer webassembly already pre-cached okay let's refresh the home page all right let's filter for webassembly no web assembly yet but if I browse the submit recipe aha so now we're seeing the.net webassembly runtime being downloaded just for this page and it gets cached so if we have other pages in this app that need.net on webassembly they can just use the already cached runtime so we're able to add interactivity to our application using either Blazer server or Blazer webassembly on a per component or per page level that's pretty cool pretty cool but would be even cooler Next Level the next level is it 11. if we could decide automatically at runtime which render mode to use like what if we did something clever where we start off users with blazer server which loads fast doesn't require downloading uh the.net runtime but we download the.net web assembly runtime in the background and then we cache it so that the next time the user comes to that to that app we can use it instead instead of having to set up a Blazer server connection what would that look like all right let's go back to the app and let's switch the render mode one more time from webassembly to Auto okay Auto render mode so this is going to allow us to make a decision at runtime which render mode do we want to use we'll go ahead and get this building and restarting there we go okay let's bring up those browser Dev tools one final time we'll clear out all our site data so we don't have anything cached already let's remove all the filters refresh okay so on the home page do we have any web assembly no web assembly do we have any web sockets no web sockets let's go to submit recipe all right so now aha so we've got the Blazer Server websocket Connection being set up but if we also filter for webassembly we can see that in the background.net.wasm is also being downloaded and cached now which one are we using well we can see that in the browser Dev console we can see that this app currently is running over our websocket so it's using Blazer server right now but in the future if the user comes back to this app let's just refresh the page as if they're revisiting the application aha it has now magically switched to use webassembly because it sees that the.net webassembly runtime has already been downloaded and installed pretty awesome so with blazerin.net 8 we're able to get the best of the server and the client using a full stack web UI experience it's pretty awesome all right let's go back to slides okay so in summary what did we just see so we are enabling full stack web UI development with blazer in.net8 with the following additional features um server side rendering with laser components um enhanced navigation and form handling streaming rendering the ability to add client interactivity per component or per page and also the ability to choose which render mode you want to use at runtime now some of these features are already available for you to try out with the latest.net 8 previews you can try out server-side rendering and streaming rendering the rest were hard at work on delivering and we expect to make available to you in upcoming dotted 8 previews as well now in addition to being able to render Blazer components from the server we're also enabling you to take a Blazer component and render it completely outside the context of an HTTP request you can take a component and render it to HTML as a string or as a stream independent of the asp.net core hosting environment and this is useful if you just want to generate some HTML fragments like maybe you want to generate some content for like an automated email or in the future we plan to use this to enable static site content generation for Blazer that's not going to come in at 8 but this is laying the foundations for for that work let me show you what this looks like okay so if we go back here and I'm going to actually go to a different Visual Studio instance now so here we have a very simple app this is actually a console app there's no asp.net core in this application but we're using this HTML renderer API to render a Blazer component and we're rendering this my component component here's my component and it's a Razer file and it's just rendering a header and the current time so pretty simple and then we render it to a string and then we're going to display it to the console output now the only one little tricky bit here is that in order to render components you need to do that in the context of a component dispatcher so that's why we have this invoke async call here that we're wrapping all the render component calls in once you do that you should be ready to go let's go ahead and execute this and there you go you can see that where'd it go where it's lost it did I close it oh my goodness oh man run it again run it again hit the button you can see that you can see there is our component content that's been rendered and so this is a really nice way to take Blazer components and use them for like some sort of HTML templating and again in the future we hope to use this for static site generation as well all right let's go back cool now we're also making some really big investments in how.net runs in browsers on webassembly whether you run your code on the server or the client we want to make sure you have the best runtime experience possible with net one of the really great improvements coming in done at eight is that we now have partial jit support with the new jit interpreter which dramatically improves the runtime performance of the.net webassembly runtime in our Benchmark tests we're seeing 20 percent faster uh UI rendering and Json serialization and deserialization is twice as fast with a new interpreter and it's just on by default you don't have to do anything to get this benefit um we're also taking advantage of the latest webassembly specs so if you're doing ahead of time compilation we're leveraging simd single instruction multiple data and webassembly exception handling so that you get even more performance when doing ahead of time compilation we're adding support for multi-threading and Dot net 8 and it is going to ship in.net8 and we've been trying to get this out for a couple of releases now it's definitely Landing in.net 8. we're adding a bunch of improvements to hot reload so that more types of edits are Now supported we just recently announced support for generics editing generic types and with hot reload so that's out all ready for you to try Blazer webassemble the apps and Donnet 8 will be fully CSP compatible that's content security policy compatible and we're also adding a new packaging format a web friendly packaging format for Donnet assemblies called Web Cil so that you can use Blazer webassembly in even more environments we're enhancing the Blazer framework uh too with a bunch of new features a quick grid is our fast and functional data grid component that we previewed with net 7. we are shipping a stable version of quick grid with.net 8. we're adding support for sections which is the ability to Define outlets for content in your application that can then be filled in by later by other components or Pages we've taught the Blazer router how to route to a particular named element and we've added some apis in Blazer server so that you can monitor the activity on your circuits and detect like if they're idle and then potentially evict them if you want to free up those server resources lastly and Jeremy's going to talk a lot about this in just a little bit we're adding some great improvements to authentication in asp.net core for Blazer that means you'll be able to build and customize your identity UI completely using Glazer let me show you just a couple of of these enhancements all right so let's let's look at quick grid real quick if you haven't seen quick grid before the easiest way to see it actually is to go to our quick grid demo site which is aka.ms slash Blazer slash quick grid and this is a Blazer webassembly app it's hosted on GitHub pages and here is quick Grid in action it's a very functional grid built it for speeds like we can do pagination that's built-in supported we can sort our columns we can filter like let's um I don't know let's look at the Olympic performance of uh Canada there we go it also supports a virtualization here's another quick grid this one's rendering you know 22 000 results but it's doing it with virtualization where it's only rendering the rows that are and fetching the rows that are currently visible so as we scroll those rows are rendered and and fetched but we can still do things like search for uh I think this is a medicinal data set so we can search for like an Alpine uh pain relief or whatever yeah so you can look look through that data set as well so quick grid very very functional very very uh convenient now if you're if you need every single Bell and whistle on a data grid component we would still strongly encourage you to check out the really awesome Blazer data grid components from the various component vendors but for something quick something convenient quick grid is is often more than sufficient so that's quick grid I also want to show you sections so let's go back to visual studio and I'm going to bring up another project all right so this project is defining a section so right here on the layout we're defining a section outlet and it has a name where you're using the name top row because this is going to show up in the the top row of our of our layout so this is like defining a little hole where we can put content and then in each of our Pages let's look at like the home page we're then using the new section content component to fill in that outlet here we're using the same name so on the home page we're just putting in some static text if we look at the counter component here we have the section content and we're putting in another another counter button like up at the top row and then in the fetch data component we're rendering the weather forecast for the the next day okay let's go ahead and run this great okay so as you can see up in the top on the home page we are rendering home and then if we look at counter we've got two counter buttons now one the main counter and then the one up in the our little section outlet and then fetch data we also are now rendering the weather for tomorrow up there on the time I love that weather by the way bracing bracing yeah it's going to be it's your hats and gloves on yeah so it's very much like section support in MVC or Razer Pages if you've ever used those Frameworks but in this case now it's available with blazer using Blazer components all right let's go back to slides okay so that's this is this is a summary of all the things that are coming for front-end developers in.net8 with blazer full stack web UI supports what we looked at a bunch of frame uh Blazer framework enhancements quick grid sections and a whole lot more and we're making big Investments in.net support on webassembly so a great experience for building beautiful web UI with.net but that's just the front end just half of it doing a whole bunch of work on the back end as well and Jeremy is going to tell us all about that next Jeremy what's happening on the back end there is so much happening on the back end so we've focused a ton on the authorization authentication identity management experience but we've also been working on apis and I want to tell you a little bit about those enhancements first before we dive into the auth story one of the things we've added for those of you using minimal apis is a new forms handling feature so that you can take the contents of a form and post it to a memo API and with an attribute it'll be able to parse those out and use those now the reason why you do that Json payloads are obviously more secure in a more common way but for things like file uploads have a well-established pattern and forms so this will allow you to take those file uploads and process them with minimal API the other thing that we started back in.net 7 was we added the problem details service so if you're not familiar with that it's a standard way of returning errors from rest endpoints and with that service it gives you more control over a very standardized way of sending it back so you can programmatically read that error detail when it comes back and in.net 8 we've expanded the surface area we've added new apis and gave you more control over what you do with that what I'm really excited to show you though is some of the improvements to the API development experience so building apis is something that people do a lot and projects can get large and complicated so anything to make that task easier can be beneficial and so what we've done is we've added a new endpoints explorer that lets you easily and quickly navigate all of the endpoints you have defined in a project in addition to that we've added support for HTTP files if you're not familiar with that format I'm going to show you what that looks like but it allows you to test your API endpoints without leaving the IDE you can do it right within and in a way that you can check it in and share it with your team we've also added helpful analyzers and analyzers I think of as kind of a coding partner that's with me as I'm writing code in it analyzes the code as I'm writing it and tells me if I'm making a mistake or potentially falling into a trap so as we identify patterns that can be problematic we add analyzers to solve for those and I'll show you what that looks like so without further Ado I want to jump into a demo and show you this now I started out with something a little simple this is the world's most simple API you hit hello on the endpoint and you get world but that's not actually what we're going to look at I made something a little more involved so let me go to index.html I've enabled static web Assets in this project and a hobby that I took up recently is astrophotography so I wanted to build a single page application that organizes my observations the photographs that I take so I've got the thumbnails for the images I can page through I can go next page previous page and I've also found when I share these photographs with people some people are Galaxy people so they want to see galaxies so we've got a quick filter for that other people are more nebula people so they like the the nebula images and if I click into this I get some details about it one interesting fact about these deep Sky targets is that they have their own coordinate system kind of like latitude and longitude so because I know where that photograph was taken I can go to a Microsoft research project called the worldwide telescope which is basically a web-based planetarium so this is the picture I took down here if I pass it off to the worldwide telescope it's going to show me exactly where that is located so that's a pretty cool feature to have that sort of coordinated in space with these pictures here like that's not like NASA taking these pictures these are pictures you took like this these are pictures taken off a deck over a streetlight oh wow yeah those are beautiful thank you now the pictures aren't what's important here we're looking at web apis so let me open up the dev tools you've seen quite a few of that or quite a bit of that today I'm going to open up this network Tab and just take off the filter for nebula and you can see we've made a simple request and this is passing some sort information it's doing a fetch if I click on the fetch we get data back so that's all straightforward now you've seen some pretty amazing Blazer demos today but we recognize that many.net developers are using JavaScript there are a few of those two yeah there are a few of those and there's a debate between what the best framework is right is it angular is it react is it view is it svelte and so I decided to kind of make a cautionary tale of this and write it in pure JavaScript so I know it's a seldom use framework but there's one Javascript file that just uses JavaScript jeremy.js exactly Jeremy JS but what's important here is that when I go to my endpoint it's as simple as awaiting a fetch going to the endpoint turning it to Json and then when I stood up my application this is a minimal API that is built from the arguments I tell it where my database is and where to get my connection string I add the problem details service that I talked about earlier I tell it to use static files so that I can serve those web assets and then here's the easiest endpoint in the world right I'm telling it for the route hello simply return world so that's a simple one but I've got more involved ones you saw that it was Slash data something so I've grouped the set of endpoints under data and we can go to this map deep Sky data so I'm going to go ahead and let's go to definition inside this we can see I've got some strongly typed methods these are taking advantage of dependency injections so I get a DB context injected here and I'm looking for a Target and I either tell you it's not found or I return the target so that's straightforward here's where some of the new experience lights up though in the older versions of this your route was just an ordinary string so you could have typed anything into it and it would have been perfectly fine until you actually tried to use the route one of the things we've done is we've lit up syntax highlighting so that you can see the different parts of the route as I look at this I can see the static Parts in red I can see the parameters are surrounded in braces but we've gone a step further I can even take this and if I want to change my constraint I get that code completion so it's telling me what constraints are available so now this is no longer just a string this is an active route that I can interact with programmatically the other thing that we did is added some analyzers to help you be successful let's say I decided to do something like this I'm going to add an exhibit which is what I call one of my target endpoints to the end so that's basically saying here's a parameter called Target it's of type exhibit which is is fine so let me go ahead and uncomment this parameter here and what we'll see is that it gets that nasty red squiggly line even though this could technically compile what it's telling me is that for run time to be able to parse this it needs to have the tri-parce method so that it knows how to bind the target so it's basically telling me now so that I can correct it in development time rather than when it's already been launched and sent out now we can add a lot of these endpoints to a project I'm just going to close this one without saving it don't save and finding those endpoints is easier now with the new endpoints Explorer so what this will do is it'll scan the project and give me a view of all of my endpoints and on these endpoints I can right click and quickly navigate to the code open it in the editor which is great but I also have this generate request nice oh wow and this is the one I want to go to generate requests what does that do so let me close out my endpoint Explorer and open up the HTTP file so if you're not familiar with this this is a file that allows me to interact with my rest endpoints directly from within visual studio so I've defined a variable at the top that has my localhost address that I'm using for development and then if I hit play here it's going to give me back I hit hello and I got back world just to prove it we'll zoom in show you that we've got a list of types here I can even go out and get a specific Target so that allows me to interact with the API see the way the data is coming back with that and it'll actually give me some more capabilities that I'll show in a second but I want to step back out of code Zoom back into slides tell you a little bit more about what we're doing in servers and middleware so to create very robust API endpoints we've added a bunch of small details and features one of those is request timeouts so this is a middleware that allows you to specify a timeout for a long running endpoint that might be doing a database fetch maybe you're depending on another service and you're fetching from that service and so you can Define this policy and it'll issue a cancellation token basically that you can then deal with and like all middleware this is configurable at a specific endpoint or at a group of endpoints so you have fine-tuned control over how you apply this the other one is a little bit of a performance I think enhancement and that's the ability to short-circuit middleware so you might have a middleware stack that includes cores and authentication authorization some custom component that parses something and sets something and does something else but for simple files like robots.txt or a 404 not found page you don't need any of that middleware so this allows you to Short Circuit that stack and just send the response directly out we've had HTTP 3 support in our server for sometime now but what we've done we've done at eight is turned it on by default so it's out of the box support and then last but not least for these features is named pipes so this is a means of communication between apps and windows and it is now possible to open and address and work with name pipes from your Kestrel server so you can have interrupt between other applications you've written and that running service which is pretty powerful let's talk about what we've done with authentication and authorization this is something that you told us was very important for us to take a look at especially in the scenario of self-hosted applications single page apps so we looked at that experience and we added several features that we believe will make a a big difference and have a huge impact the first one is client-friendly endpoints for identity management so if you're familiar with the existing experience I'll show you how that's architected but you basically have a server-side solution that you can customize this gives you everything as an endpoint that you can interface with from whatever component you want whether it's a spa application client or a mobile client for example that needs to work with identity for scenarios like mobile that don't support cookie authentication which is what we do out of the box we've also added support for tokens but without the complexity and overhead of configuring a full oidc server now we've shipped an oid server in the Box for some time that server became a commercially licensed server so we've removed that to replace it with this piece but if you still need that full oidc compliance that's still available that's there it's a great product that's used by a lot of people but if you need something simple then that's what we're providing for you out of the box this is what asp.net identity looks like in the Box we've got the identity manager which is a set of apis you talk to on the server to manage identity we've got a identity store abstraction so that you can use different data stores and we've got a default implementation out of the box now what we used to ship were the server side Razer page uis what we've added are these endpoints so that your client UI can participate and that you don't have to build these endpoints yourself because we know some of you to create a spa experience have been having to stand up and customize that experience so to show you what that looks like I'm going to jump back into my my demo and one of the things that I showed you was that each observation has a Celestial coordinate well there's also a coordinate I'm interested in which is where I took the photograph so I go to different sites but the problem is most of my observations happen either on my front deck or my back patio and the last thing I want to do is have someone get the GPS coordinates to my deck that would just be weird so what I want to do is protect this behind an ape behind authentication and authorization so that only I can see my locations and and they don't leak for someone else so if I click on this right now you can see login check failed you must be logged in that's great so let's see what it takes to add to an application that has no authentication whatsoever we're going to add these features to it so the first thing I'm going to do is in my HTML page I've conveniently hidden this little login box so I'm just gonna go ahead and remove this code so that we unhide it and then through the power of hot reload if I bounce back over we've got the dialog there so that's great let's go into our minimal API so in my program setup I've referenced identity and because I've referenced Entity framework core I need a database to store the user data so I'm going to go ahead and Define that now we've got a base DB context that we ship out of the box that's the identity context with a base user and then I'm inheriting that and all I'm doing is just making sure the database is created why because this is running in memory and I don't want to be responsible for storing anyone's credentials so I want it to just be blown away when the the demo is done running now that I have that I can tell the application that I want to use this new identity so I have to open the connection to my database I add authorization so that tells the services we're going to use authorization and I tell it which DB context we're using to store that identity data finally I tell it I would love these new endpoints these API endpoints to be able to work with identity through the apis and last but not least on this one is just telling it where to Route those endpoints so I'm putting it under a slash identity so the one thing that I forgot to do and didn't have time to put in was a registration page normally I'd be stuck but fortunately with the HTTP file I can come over to this side and with my secret build password I can go ahead and register right here you might have to change that password after this Jeremy well actually it's it's telling me it's not a good password so I got some problem details back that tell me I need a alphanumeric oh yeah yeah so let's add some excitement to this demo and do that right there and then if we run that all right I get a okay Response Code so let me copy this password because I don't trust myself to remember it to type it and the first thing I'm going to do is do a made up password so that we can assure ourselves that there's no hid magic that just automatically logs me in so let's do a login here and login failed please try again okay that's perfect and it would help if I actually had my username correct here but that's fine and then let's paste the password in and see what happens and login successfully logged in so the code for that by the way if we do a search for login we've got a little bit of UI for that and then we've got this that makes a call to an indirection of a redirection to another no seriously this is it right here the weight fetch login cookie mode equals true and because I'm using cookies subsequent requests should just work so I should be able to come back over here and if I open up and I look for my personal location we're going to see your location let's see well this is a very like I feel small cozy venue I trust everyone here so it's okay if I try to see that I don't think they're going to take an intro to anyone else so there's the uh that is a nice rig that's the location now there is one problem though if I come back here and I've I've already logged in right so I've got my HTTP file I should be able to come up here and on that personal Target I should be able to do a get but I actually get an unauthorized and the reason why is because Visual Studio is not keeping track of cookies for me so I need to go to a token based login so let's log in now and here I've got a super token and I call it a super token because it is huge and we're going to come here and grab this token and Ctrl C then down here I've got a variable that tells me to paste it here so very user friendly interface for this demo we're going to just shave the quotes off the end now what this is saying is do a get and pass that token in the header so I'm going to hit play and it gives me back a location it no longer tells me unauthorized and I actually used a different Target here so I told you I do the the front deck and the back patio so let's see which one this is and we'll paste that in and we go to another beautiful site in Chile okay gorgeous and that is what I want to share on off I have one more feature on apis and that's ahead of time compilation what this allows you to do is compile your apis into a self-contained executable that has a reduced footprint on disk has a faster startup time and reduced memory demand there is a lot involved with ahead of time compilation so I'm going to leave the details of that to distinguished engineer David Fowler and principal architect Damian Edmonds they have a session tomorrow that is a deep dive into this feature so what we talked about were changes to our middleware and our server side we talked about a client-friendly identity that I would love to hear from you what you think of that if it's useful to you and how we can make that better and we talked about API productivity things like turning a simple string into an actual interactive route and with that I'm going to turn it back over to Dan all right wow that was great API productivity improvements yeah go ahead go ahead API productivity improvements ah looks awesome token based on a cookie based stuff that looks great if you're interested in learning more about web development with.net there are a lot of great resources on Microsoft learn whether you're completely new or you just want to polish up your existing skills check out the QR code and you'll get on the learning path there's also an open and friendly.net Community available on all your favorite favorite platforms that you can engage with to get your questions answered we hope you enjoyed learning about the new stuff coming in.net8 today if you haven't already go ahead and download.net to get started on your next great web project and please try out the latest.net8 previews let us know what you think thank you all for being here thank you for listening [Applause]
Info
Channel: Tech of the day
Views: 2,605
Rating: undefined out of 5
Keywords: .net 8, .net core, dot net, dotnet 8, how to code, software engineering, microsoft, microsoft build, microsoft build 2023, what's new in dotnet, whats new in dotnet, whats new in dotnet 8, microsoft mvp, .net 7, asp.net core, nick chapsas, claudio bernasconi, .net 8 preview, dot net tutorial for beginners, dot net full course, visual studio, dotnet core
Id: mFljzcpxdAA
Channel Id: undefined
Length: 45min 34sec (2734 seconds)
Published: Thu May 25 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.