From b4c486f6d5fad7970db7105f8b3515d097fcfb99 Mon Sep 17 00:00:00 2001 From: Sumit Ghosh <13281246+sughosneo@users.noreply.github.com> Date: Wed, 18 Nov 2020 22:20:57 +0530 Subject: [PATCH 1/3] Included net-5.0 specific updates --- .../app-startup.md | 10 +-- .../architecture-comparison.md | 2 +- .../blazor-for-web-forms-developers/config.md | 8 +-- .../blazor-for-web-forms-developers/data.md | 4 +- .../hosting-models.md | 6 +- .../introduction.md | 12 ++-- .../migration.md | 27 ++++---- .../project-structure.md | 64 ++++++++++--------- .../security-authentication-authorization.md | 56 ++++++++-------- 9 files changed, 97 insertions(+), 92 deletions(-) diff --git a/docs/architecture/blazor-for-web-forms-developers/app-startup.md b/docs/architecture/blazor-for-web-forms-developers/app-startup.md index 7fb9322fb21a5..6fb76e5fd032f 100644 --- a/docs/architecture/blazor-for-web-forms-developers/app-startup.md +++ b/docs/architecture/blazor-for-web-forms-developers/app-startup.md @@ -3,7 +3,7 @@ title: App startup description: Learn how to define the startup logic for your app. author: csharpfritz ms.author: jefritz -ms.date: 02/25/2020 +ms.date: 11/20/2020 --- # App startup @@ -16,13 +16,13 @@ The default web forms `Application_Start` method has grown in purpose over years - `RouteConfig` - Application URL routing - `BundleConfig` - CSS and JavaScript bundling and minification -Each of these individual files reside in the `App_Start` folder and run only once at the start of our application. `RouteConfig` in the default project template adds the `FriendlyUrlSettings` for web forms to allow application URLs to omit the `.ASPX` file extension. The default template also contains a directive that provides permanent HTTP redirect status codes (HTTP 301) for the `.ASPX` pages to the friendly URL with the file name that omits the extension. +Each of these individual files resides in the `App_Start` folder and run only once at the start of our application. `RouteConfig` in the default project template adds the `FriendlyUrlSettings` for web forms to allow application URLs to omit the `.ASPX` file extension. The default template also contains a directive that provides permanent HTTP redirect status codes (HTTP 301) for the `.ASPX` pages to the friendly URL with the file name that omits the extension. With ASP.NET Core and Blazor, these methods are either simplified and consolidated into the `Startup` class or they are eliminated in favor of common web technologies. ## Blazor Server Startup Structure -Blazor Server applications reside on top of an ASP.NET Core 3.0 or later application. ASP.NET Core web applications are configured through a pair of methods in the `Startup.cs` class on the root folder of the application. The Startup class's default content is listed below +Blazor Server applications reside on top of an ASP.NET Core 3.0 or later version. ASP.NET Core web applications are configured through a pair of methods in the `Startup.cs` class on the root folder of the application. The Startup class's default content is listed below ```csharp public class Startup @@ -73,7 +73,7 @@ public class Startup Like the rest of ASP.NET Core, the Startup class is created with dependency injection principles. The `IConfiguration` is provided to the constructor and stashed in a public property for later access during configuration. -The `ConfigureServices` method introduced in ASP.NET Core allows for the various ASP.NET Core framework services to be configured for the framework's built-in dependency injection container. The various `services.Add*` methods add services that enable features such as authentication, razor pages, MVC controller routing, SignalR, and Blazor Server interactions among many others. This method was not needed in web forms, as the parsing and handling of the ASPX, ASCX, ASHX, and ASMX files was defined by referencing ASP.NET in the web.config configuration file. More information about dependency injection in ASP.NET Core is available in the [online documentation](/aspnet/core/fundamentals/dependency-injection). +The `ConfigureServices` method introduced in ASP.NET Core allows for the various ASP.NET Core framework services to be configured for the framework's built-in dependency injection container. The various `services.Add*` methods add services that enable features such as authentication, razor pages, MVC controller routing, SignalR, and Blazor Server interactions among many others. This method was not needed in web forms, as the parsing and handling of the ASPX, ASCX, ASHX, and ASMX files were defined by referencing ASP.NET in the web.config configuration file. More information about dependency injection in ASP.NET Core is available in the [online documentation](/aspnet/core/fundamentals/dependency-injection). The `Configure` method introduces the concept of the HTTP pipeline to ASP.NET Core. In this method, we declare from top to bottom the [Middleware](middleware.md) that will handle every request sent to our application. Most of these features in the default configuration were scattered across the web forms configuration files and are now in one place for ease of reference. @@ -83,7 +83,7 @@ Next, an unexpected configuration method is listed to `UseStaticFiles`. In ASP. The next line is the first that replicates one of the configuration options from web forms: `UseRouting`. This method adds the ASP.NET Core router to the pipeline and it can be either configured here or in the individual files that it can consider routing to. More information about routing configuration can be found in the [Routing section](pages-routing-layouts.md). -The final statement in this method defines the endpoints that ASP.NET Core is listening on. These are the web accessible locations that you can access on the web server and receive some content handled by .NET and returned to you. The first entry, `MapBlazorHub` configures a SignalR hub for use in providing the real-time and persistent connection to the server where the state and rendering of Blazor components is handled. The `MapFallbackToPage` method call indicates the web-accessible location of the page that starts the Blazor application and also configures the application to handle deep-linking requests from the client-side. You will see this feature at work if you open a browser and navigate directly to Blazor handled route in your application, such as `/counter` in the default project template. The request gets handled by the *_Host.cshtml* fallback page, which then runs the Blazor router and renders the counter page. +The final statement in this method defines the endpoints that ASP.NET Core is listening on. These routes are the web accessible locations that you can access on the web server and receive some content handled by .NET and returned to you. The first entry, `MapBlazorHub` configures a SignalR hub for use in providing the real-time and persistent connection to the server where the state and rendering of Blazor components is handled. The `MapFallbackToPage` method call indicates the web-accessible location of the page that starts the Blazor application and also configures the application to handle deep-linking requests from the client-side. You will see this feature at work if you open a browser and navigate directly to Blazor handled route in your application, such as `/counter` in the default project template. The request gets handled by the *_Host.cshtml* fallback page, which then runs the Blazor router and renders the counter page. ## Upgrading the BundleConfig Process diff --git a/docs/architecture/blazor-for-web-forms-developers/architecture-comparison.md b/docs/architecture/blazor-for-web-forms-developers/architecture-comparison.md index 40958fc59a081..baab3005b61d8 100644 --- a/docs/architecture/blazor-for-web-forms-developers/architecture-comparison.md +++ b/docs/architecture/blazor-for-web-forms-developers/architecture-comparison.md @@ -4,7 +4,7 @@ description: Learn how the architectures of ASP.NET Web Forms and Blazor compare author: danroth27 ms.author: daroth no-loc: [Blazor] -ms.date: 09/11/2019 +ms.date: 11/20/2020 --- # Architecture comparison of ASP.NET Web Forms and Blazor diff --git a/docs/architecture/blazor-for-web-forms-developers/config.md b/docs/architecture/blazor-for-web-forms-developers/config.md index f3223ab66958a..e91a838e2b72f 100644 --- a/docs/architecture/blazor-for-web-forms-developers/config.md +++ b/docs/architecture/blazor-for-web-forms-developers/config.md @@ -4,7 +4,7 @@ description: Learn how to configure Blazor apps without using ConfigurationManag author: csharpfritz ms.author: jefritz no-loc: [Blazor] -ms.date: 04/01/2020 +ms.date: 11/20/2020 --- # App configuration @@ -21,9 +21,9 @@ With ASP.NET Core and server-side Blazor, the *web.config* file MAY be present i ASP.NET Core recognizes there are many configuration sources you may want to use for your app. The framework attempts to offer you the best of these features by default. Configuration is read and aggregated from these various sources by ASP.NET Core. Later loaded values for the same configuration key take precedence over earlier values. -ASP.NET Core was designed to be cloud-aware and to make configuration of apps easier for both operators and developers. ASP.NET Core is environment-aware and knows if it's running in your `Production` or `Development` environment. The environment indicator is set in the `ASPNETCORE_ENVIRONMENT` system environment variable. If no value is configured, the app defaults to running in the `Production` environment. +ASP.NET Core was designed to be cloud-aware and to make the configuration of apps easier for both operators and developers. ASP.NET Core is environment-aware and knows if it's running in your `Production` or `Development` environment. The environment indicator is set in the `ASPNETCORE_ENVIRONMENT` system environment variable. If no value is configured, the app defaults to running in the `Production` environment. -Your app can trigger and add configuration from several sources based on the environment's name. By default, configuration is loaded from the following resources in the order listed: +Your app can trigger and add configuration from several sources based on the environment's name. By default, the configuration is loaded from the following resources in the order listed: 1. *appsettings.json* file, if present 1. *appsettings.{ENVIRONMENT_NAME}.json* file, if present @@ -57,7 +57,7 @@ User secrets are: * Configuration values that are stored in a JSON file on the developer's workstation, outside of the app development folder. * Only loaded when running in the `Development` environment. * Associated with a specific app. -* Managed with the .NET Core CLI's `user-secrets` command. +* Managed with the .NET CLI's `user-secrets` command. Configure your app for secrets storage by executing the `user-secrets` command: diff --git a/docs/architecture/blazor-for-web-forms-developers/data.md b/docs/architecture/blazor-for-web-forms-developers/data.md index 0b0b4a2e33265..009e28f33a747 100644 --- a/docs/architecture/blazor-for-web-forms-developers/data.md +++ b/docs/architecture/blazor-for-web-forms-developers/data.md @@ -4,7 +4,7 @@ description: Learn how to access and handle data in ASP.NET Web Forms and Blazor author: csharpfritz ms.author: jefritz no-loc: [Blazor] -ms.date: 09/08/2020 +ms.date: 11/20/2020 --- # Work with data @@ -23,7 +23,7 @@ ADO.NET is the low-level approach to interacting with a database. Your apps coul ## Entity Framework -Entity Framework (EF) is the open source object-relational mapping framework maintained by the .NET Foundation. Initially released with .NET Framework, EF allows for generating code for the database connections, storage schemas, and interactions. With this abstraction, you can focus on your app's business rules and allow the database to be managed by a trusted database administrator. In .NET Core, you can use an updated version of EF called EF Core. EF Core helps generate and maintain the interactions between your code and the database with a series of commands that are available for you using the `dotnet ef` command-line tool. Let's take a look at a few samples to get you working with a database. +Entity Framework (EF) is the open source object-relational mapping framework maintained by the .NET Foundation. Initially released with .NET Framework, EF allows for generating code for the database connections, storage schemas, and interactions. With this abstraction, you can focus on your app's business rules and allow the database to be managed by a trusted database administrator. In .NET, you can use an updated version of EF called EF Core. EF Core helps generate and maintain the interactions between your code and the database with a series of commands that are available for you using the `dotnet ef` command-line tool. Let's take a look at a few samples to get you working with a database. ### EF Code First diff --git a/docs/architecture/blazor-for-web-forms-developers/hosting-models.md b/docs/architecture/blazor-for-web-forms-developers/hosting-models.md index c077c291f9e53..f0f5826b3b98e 100644 --- a/docs/architecture/blazor-for-web-forms-developers/hosting-models.md +++ b/docs/architecture/blazor-for-web-forms-developers/hosting-models.md @@ -4,7 +4,7 @@ description: Learn the different ways to host a Blazor app, including in the bro author: danroth27 ms.author: daroth no-loc: [Blazor, WebAssembly] -ms.date: 09/11/2019 +ms.date: 11/20/2020 --- # Blazor app hosting models @@ -58,8 +58,8 @@ The downsides of the Blazor WebAssembly hosting model are: Conversely, the Blazor Server hosting model offers the following benefits: - Download size is much smaller than a client-side app, and the app loads much faster. -- The app takes full advantage of server capabilities, including use of any .NET Core-compatible APIs. -- .NET Core on the server is used to run the app, so existing .NET tooling, such as debugging, works as expected. +- The app takes full advantage of server capabilities, including use of any .NET compatible APIs. +- .NET on the server is used to run the app, so existing .NET tooling, such as debugging, works as expected. - Thin clients are supported. For example, server-side apps work with browsers that don't support WebAssembly and on resource-constrained devices. - The app's .NET/C# code base, including the app's component code, isn't served to clients. diff --git a/docs/architecture/blazor-for-web-forms-developers/introduction.md b/docs/architecture/blazor-for-web-forms-developers/introduction.md index 9cf663afdb4e7..12042370e9935 100644 --- a/docs/architecture/blazor-for-web-forms-developers/introduction.md +++ b/docs/architecture/blazor-for-web-forms-developers/introduction.md @@ -4,7 +4,7 @@ description: An introduction to Blazor and writing full-stack web apps with .NET author: danroth27 ms.author: daroth no-loc: [Blazor, WebAssembly] -ms.date: 09/11/2019 +ms.date: 11/20/2020 --- # An introduction to Blazor for ASP.NET Web Forms developers @@ -25,7 +25,7 @@ When .NET and ASP.NET Web Forms first shipped, the platform ecosystem looked muc Most modern web frameworks are now also open-source, which has a number of benefits. Users aren't beheld to a single project owner to fix bugs and add features. Open-source projects provide improved transparency on development progress and upcoming changes. Open-source projects enjoy contributions from an entire community, and they foster a supportive open-source ecosystem. Despite the risks of open-source, many consumers and contributors have found suitable mitigations that enable them to enjoy the benefits of an open-source ecosystem in a safe and reasonable way. Examples of such mitigations include contributor license agreements, friendly licenses, pedigree scans, and supporting foundations. -The .NET community has embraced both cross-platform support and open-source. .NET Core is an open-source and cross-platform implementation of .NET that runs on a plethora of platforms, including Windows, macOS, and various Linux distributions. Xamarin provides Mono, an open-source version of .NET. Mono runs on Android, iOS, and a variety of other form factors, including watches and smart TVs. Microsoft has announced that [.NET 5](https://devblogs.microsoft.com/dotnet/introducing-net-5/) will reconcile .NET Core and Mono into "a single .NET runtime and framework that can be used everywhere and that has uniform runtime behaviors and developer experiences." +The .NET community has embraced both cross-platform support and open-source. .NET Core is an open-source and cross-platform implementation of .NET that runs on a plethora of platforms, including Windows, macOS, and various Linux distributions. Xamarin provides Mono, an open-source version of .NET. Mono runs on Android, iOS, and a variety of other form factors, including watches and smart TVs. Microsoft has released [.NET 5](https://devblogs.microsoft.com/dotnet/announcing-net-5-0/) that reconciled .NET Core and Mono into "a single .NET runtime and framework that can be used everywhere and that has uniform runtime behaviors and developer experiences." Will ASP.NET Web Forms benefit from the move to open-source and cross-platform support? The answer, unfortunately, is no, or at least not to the same extent as the rest of the platform. The .NET team [recently made it clear](https://devblogs.microsoft.com/dotnet/net-core-is-the-future-of-net/) that ASP.NET Web Forms won't be ported to .NET Core or .NET 5. Why is that? @@ -47,11 +47,11 @@ But bridging two different platforms and ecosystems (.NET and JavaScript) comes In 2015, the major browser vendors joined forces in a W3C Community Group to create a new open web standard called WebAssembly. WebAssembly is a byte code for the Web. If you can compile your code to WebAssembly, it can then run on any browser on any platform at near native speed. Initial efforts focused on C/C++. The result was a dramatic demonstration of running native 3D graphics engines directly in the browser without plugins. WebAssembly has since been standardized and implemented by all major browsers. -Work on running .NET on WebAssembly was announced in late 2017 and is expected to ship in 2020, including support from .NET 5. The ability to run .NET code directly in the browser enables full-stack web development with .NET. +Work on running .NET on WebAssembly was announced in late 2017 and released in 2020, including support from .NET 5. The ability to run .NET code directly in the browser enables full-stack web development with .NET. ## Blazor: full-stack web development with .NET -On its own, the ability to run .NET code in a browser doesn't provide an end-to-end experience for creating client-side web apps. That's where Blazor comes in. Blazor is a client-side web UI framework based on C# instead of JavaScript. Blazor can run directly in the browser via WebAssembly. No browser plugins are required. Alternatively, Blazor apps can run server-side on .NET Core and handle all user interactions over a real-time connection with the browser. +On its own, the ability to run .NET code in a browser doesn't provide an end-to-end experience for creating client-side web apps. That's where Blazor comes in. Blazor is a client-side web UI framework based on C# instead of JavaScript. Blazor can run directly in the browser via WebAssembly. No browser plugins are required. Alternatively, Blazor apps can run server-side on .NET and handle all user interactions over a real-time connection with the browser. Blazor has great tooling support in Visual Studio and Visual Studio Code. The framework also includes a full UI component model and has built-in facilities for: @@ -68,12 +68,12 @@ This book provides an introduction to Blazor that is catered specifically to ASP - How to build Blazor apps. - How Blazor works. -- How Blazor relates to .NET Core. +- How Blazor relates to .NET. - Reasonable strategies for migrating existing ASP.NET Web Forms apps to Blazor where appropriate. ## Get started with Blazor -Getting started with Blazor is easy. Go to and follow the links to install the appropriate .NET Core SDK and Blazor project templates. You'll also find instructions for setting up the Blazor tooling in Visual Studio or Visual Studio Code. +Getting started with Blazor is easy. Go to and follow the links to install the appropriate .NET SDK and Blazor project templates. You'll also find instructions for setting up the Blazor tooling in Visual Studio or Visual Studio Code. >[!div class="step-by-step"] >[Previous](index.md) diff --git a/docs/architecture/blazor-for-web-forms-developers/migration.md b/docs/architecture/blazor-for-web-forms-developers/migration.md index 1ecb579dc4c6c..63af1e38b8691 100644 --- a/docs/architecture/blazor-for-web-forms-developers/migration.md +++ b/docs/architecture/blazor-for-web-forms-developers/migration.md @@ -4,7 +4,7 @@ description: Learn how to approach migrating an existing ASP.NET Web Forms app t author: twsouthwick ms.author: tasou no-loc: [Blazor, WebAssembly] -ms.date: 09/19/2019 +ms.date: 11/20/2020 --- # Migrate from ASP.NET Web Forms to Blazor @@ -25,7 +25,7 @@ If these or other new features are compelling enough, there may be value in migr As described in the [hosting models](hosting-models.md) chapter, a Blazor app can be hosted in two different ways: server-side and client-side. The server-side model uses ASP.NET Core SignalR connections to manage the DOM updates while running any actual code on the server. The client-side model runs as WebAssembly within a browser and requires no server connections. There are a number of differences that may affect which is best for a specific app: -- Running as WebAssembly is still in development and may not support all features (such as threading) at the current time +- Running as WebAssembly doesn't support all features (such as threading) at the current time - Chatty communication between the client and server may cause latency issues in server-side mode - Access to databases and internal or protected services require a separate service with client-side hosting @@ -33,11 +33,11 @@ At the time of writing, the server-side model more closely resembles Web Forms. ## Create a new project -This initial migration step is to create a new project. This project type is based on the SDK style projects of .NET Core and simplifies much of the boilerplate that was used in previous project formats. For more detail, please see the chapter on [Project Structure](project-structure.md). +This initial migration step is to create a new project. This project type is based on the SDK style projects of .NET and simplifies much of the boilerplate that was used in previous project formats. For more detail, please see the chapter on [Project Structure](project-structure.md). Once the project has been created, install the libraries that were used in the previous project. In older Web Forms projects, you may have used the *packages.config* file to list the required NuGet packages. In the new SDK-style project, *packages.config* has been replaced with `` elements in the project file. A benefit to this approach is that all dependencies are installed transitively. You only list the top-level dependencies you care about. -Many of the dependencies you're using are available for .NET Core, including Entity Framework 6 and log4net. If there's no .NET Core or .NET Standard version available, the .NET Framework version can often be used. Your mileage may vary. Any API used that isn't available in .NET Core causes a runtime error. Visual Studio notifies you of such packages. A yellow icon appears on the project's **References** node in **Solution Explorer**. +Many of the dependencies you're using are available for .NET, including Entity Framework 6 and log4net. If there's no .NET or .NET Standard version available, the .NET Framework version can often be used. Your mileage may vary. Any API used that isn't available in .NET causes a runtime error. Visual Studio notifies you of such packages. A yellow icon appears on the project's **References** node in **Solution Explorer**. In the Blazor-based eShop project, you can see the packages that are installed. Previously, the *packages.config* file listed every package used in the project, resulting in a file almost 50 lines long. A snippet of *packages.config* is: @@ -72,12 +72,13 @@ The Blazor project lists the dependencies you require within an `` el ```xml - - + + + ``` -One NuGet package that simplifies the life of Web Forms developers is the [Windows Compatibility Pack](../../core/porting/windows-compat-pack.md). Although .NET Core is cross-platform, some features are only available on Windows. Windows-specific features are made available by installing the compatibility pack. Examples of such features include the Registry, WMI, and Directory Services. The package adds around 20,000 APIs and activates many services with which you may already be familiar. The eShop project doesn't require the compatibility pack; but if your projects use Windows-specific features, the package eases the migration efforts. +One NuGet package that simplifies the life of Web Forms developers is the [Windows Compatibility Pack](../../core/porting/windows-compat-pack.md). Although .NET is cross-platform, some features are only available on Windows. Windows-specific features are made available by installing the compatibility pack. Examples of such features include the Registry, WMI, and Directory Services. The package adds around 20,000 APIs and activates many services with which you may already be familiar. The eShop project doesn't require the compatibility pack; but if your projects use Windows-specific features, the package eases the migration efforts. ## Enable startup process @@ -237,15 +238,15 @@ public class Startup } ``` -One significant change you may notice from Web Forms is the prominence of DI. DI has been a guiding principle in the ASP.NET Core design. It supports customization of almost all aspects of the ASP.NET Core framework. There's even a built-in service provider that can be used for many scenarios. If more customization is required, it can be supported by the many community projects. For example, you can carry forward your third-party DI library investment. +One significant change you may notice from Web Forms is the prominence of DI. DI has been a guiding principle in the ASP.NET Core design. It supports customization of almost all aspects of the ASP.NET Core framework. There's even a built-in service provider that can be used for many scenarios. If more customization is required, it can be supported by many community projects. For example, you can carry forward your third-party DI library investment. -In the original eShop app, there's some configuration for session management. Since server-side Blazor uses ASP.NET Core SignalR for communication, session state isn't supported as the connections may occur independent of an HTTP context. An app that uses session state requires rearchitecting before running as a Blazor app. +In the original eShop app, there's some configuration for session management. Since server-side Blazor uses ASP.NET Core SignalR for communication, the session state isn't supported as the connections may occur independent of an HTTP context. An app that uses the session state requires rearchitecting before running as a Blazor app. For more information about app startup, see [App startup](app-startup.md). ## Migrate HTTP modules and handlers to middleware -HTTP modules and handlers are common patterns in Web Forms to control the HTTP request pipeline. Classes that implement `IHttpModule` or `IHttpHandler` could be registered and process incoming requests. Web Forms configures modules and handlers in the *web.config* file. Web Forms is also heavily based on app lifecycle event handling. ASP.NET Core uses middleware instead. Middleware is registered in the `Configure` method of the `Startup` class. Middleware execution order is determined by the registration order. +HTTP modules and handlers are common patterns in Web Forms to control the HTTP request pipeline. Classes that implement `IHttpModule` or `IHttpHandler` could be registered and process incoming requests. Web Forms configure modules and handlers in the *web.config* file. Web Forms is also heavily based on app lifecycle event handling. ASP.NET Core uses middleware instead. Middleware is registered in the `Configure` method of the `Startup` class. Middleware execution order is determined by the registration order. In the [Enable startup process](#enable-startup-process) section, a lifecycle event was raised by Web Forms as the `Application_BeginRequest` method. This event isn't available in ASP.NET Core. One way to achieve this behavior is to implement middleware as seen in the *Startup.cs* file example. This middleware does the same logic and then transfers control to the next handler in the middleware pipeline. @@ -550,11 +551,11 @@ In Blazor, the equivalent markup is provided in a *Create.razor* file: ``` -The `EditForm` context includes validation support and can be wrapped around input. Data annotations are a common way to add validation. Such validation support can be added via the `DataAnnotationsValidator` component. For more information on this mechanism, see [ASP.NET Core Blazor forms and validation](/aspnet/core/blazor/forms-validation). +The `EditForm` context includes validation support and can be wrapped around an input. Data annotations are a common way to add validation. Such validation support can be added via the `DataAnnotationsValidator` component. For more information on this mechanism, see [ASP.NET Core Blazor forms and validation](/aspnet/core/blazor/forms-validation). ## Migrate configuration -In a Web Forms project, configuration data is most commonly stored in the *web.config* file. The configuration data is accessed with `ConfigurationManager`. Services were often required to parse objects. With .NET Framework 4.7.2, composability was added to configuration via `ConfigurationBuilders`. These builders allowed developers to add various sources for configuration that was then composed at runtime to retrieve the necessary values. +In a Web Forms project, configuration data is most commonly stored in the *web.config* file. The configuration data is accessed with `ConfigurationManager`. Services were often required to parse objects. With .NET Framework 4.7.2, composability was added to the configuration via `ConfigurationBuilders`. These builders allowed developers to add various sources for the configuration that was then composed at runtime to retrieve the necessary values. ASP.NET Core introduced a flexible configuration system that allows you to define the configuration source or sources used by your app and deployment. The `ConfigurationBuilder` infrastructure that you may be using in your Web Forms app was modeled after the concepts used in the ASP.NET Core configuration system. @@ -608,7 +609,7 @@ By default, environment variables, JSON files (*appsettings.json* and *appsettin ## Migrate data access -Data access is an important aspect of any app. The eShop project stores catalog information in a database and retrieves the data with Entity Framework (EF) 6. Since EF 6 is supported in .NET Core 3.0, the project can continue to use it. +Data access is an important aspect of any app. The eShop project stores catalog information in a database and retrieves the data with Entity Framework (EF) 6. Since EF 6 is supported in .NET 5.0, the project can continue to use it. The following EF-related changes were necessary to eShop: diff --git a/docs/architecture/blazor-for-web-forms-developers/project-structure.md b/docs/architecture/blazor-for-web-forms-developers/project-structure.md index fb06fa942c64c..442c3ca40cd1d 100644 --- a/docs/architecture/blazor-for-web-forms-developers/project-structure.md +++ b/docs/architecture/blazor-for-web-forms-developers/project-structure.md @@ -4,7 +4,7 @@ description: Learn how the project structures of ASP.NET Web Forms and Blazor pr author: danroth27 ms.author: daroth no-loc: [Blazor, WebAssembly] -ms.date: 09/11/2019 +ms.date: 11/20/2020 --- # Project structure for Blazor apps @@ -14,13 +14,13 @@ To create your first Blazor app, follow the instructions in the [Blazor getting ## Project file -Blazor Server apps are .NET Core projects. The project file for the Blazor Server app is about as simple as it can get: +Blazor Server apps are .NET projects. The project file for the Blazor Server app is about as simple as it can get: ```xml - netcoreapp3.0 + net5.0 @@ -29,32 +29,26 @@ Blazor Server apps are .NET Core projects. The project file for the Blazor Serve The project file for a Blazor WebAssembly app looks slightly more involved (exact version numbers may vary): ```xml - + - netstandard2.0 - 3.0 + net5.0 - - - - - - - - + + + ``` -Blazor WebAssembly projects target .NET Standard instead of .NET Core because they run in the browser on a WebAssembly-based .NET runtime. You can't install .NET into a web browser like you can on a server or developer machine. Consequently, the project references the Blazor framework using individual package references. +Blazor WebAssembly project targets `Microsoft.NET.Sdk.BlazorWebAssembly` instead of `Microsoft.NET.Sdk.Web` sdk because they run in the browser on a WebAssembly-based .NET runtime. You can't install .NET into a web browser like you can on a server or developer machine. Consequently, the project references the Blazor framework using individual package references. -By comparison, a default ASP.NET Web Forms project includes almost 300 lines of XML in its *.csproj* file, most of which is explicitly listing the various code and content files in the project. Many of the simplifications in the .NET Core- and .NET Standard-based projects come from the default targets and properties imported by referencing the `Microsoft.NET.Sdk.Web` SDK, often referred to as simply the Web SDK. The Web SDK includes wildcards and other conveniences that simplify inclusion of code and content files in the project. You don't need to list the files explicitly. When targeting .NET Core, the Web SDK also adds framework references to both the .NET Core and ASP.NET Core shared frameworks. The frameworks are visible from the **Dependencies** > **Frameworks** node in the **Solution Explorer** window. The shared frameworks are collections of assemblies that were installed on the machine when installing .NET Core. +By comparison, a default ASP.NET Web Forms project includes almost 300 lines of XML in its *.csproj* file, most of which is explicitly listing the various code and content files in the project. With the release of `.NET 5` both `Blazor Server` and `Blazor WebAssembly` app can easily share one unified runtime. -Although they're supported, individual assembly references are less common in .NET Core projects. Most project dependencies are handled as NuGet package references. You only need to reference top-level package dependencies in .NET Core projects. Transitive dependencies are included automatically. Instead of using the *packages.config* file commonly found in ASP.NET Web Forms projects to reference packages, package references are added to the project file using the `` element. +Although they're supported, individual assembly references are less common in .NET projects. Most project dependencies are handled as NuGet package references. You only need to reference top-level package dependencies in .NET projects. Transitive dependencies are included automatically. Instead of using the *packages.config* file commonly found in ASP.NET Web Forms projects to reference packages, package references are added to the project file using the `` element. ```xml @@ -146,7 +140,7 @@ We'll look in greater detail at routing in Blazor in the [Pages, routing, and la ## Layout -In ASP.NET Web Forms apps, common page layout is handled using master pages (*Site.Master*). In Blazor apps, page layout is handled using layout components (*Shared/MainLayout.razor*). Layout components will be discussed in more detail in [Page, routing, and layouts](./pages-routing-layouts.md) section. +In ASP.NET Web Forms apps, a common page layout is handled using master pages (*Site.Master*). In Blazor apps, the page layout is handled using layout components (*Shared/MainLayout.razor*). Layout components will be discussed in more detail in [Page, routing, and layouts](./pages-routing-layouts.md) section. ## Bootstrap Blazor @@ -190,39 +184,49 @@ The script reference to *_framework/blazor.server.js* establishes the real-time ``` -In the Blazor WebAssembly app, the host page is a simple static HTML file under *wwwroot/index.html*. The `` element is used to indicate where the root component should be rendered. +In the Blazor WebAssembly app, the host page is a simple static HTML file under *wwwroot/index.html*. The `
` element with id named `app` is used to indicate where the root component should be rendered. ```html + - + BlazorApp2 - + + + - Loading... +
Loading...
+
+ An unhandled error has occurred. + Reload + 🗙 +
+ + ``` -The specific component to render is configured in the app's `Startup.Configure` method with a corresponding CSS selector indicating where the component should be rendered. +The root component to render is configured in the app's `Program.Main` method with the flexibility to register different services through dependency injection.You can refer add services to an app in [Blazor WebAssembly](https://docs.microsoft.com/aspnet/core/blazor/fundamentals/dependency-injection?view=aspnetcore-5.0#blazor-webassembly) ```csharp -public class Startup +public class Program { - public void ConfigureServices(IServiceCollection services) + public static async Task Main(string[] args) { - } + var builder = WebAssemblyHostBuilder.CreateDefault(args); + builder.RootComponents.Add("#app"); - public void Configure(IComponentsApplicationBuilder app) - { - app.AddComponent("app"); + .... + .... } } ``` @@ -240,7 +244,7 @@ To run the Blazor WebAssembly app, choose one of the following approaches: - Run the client project directly using the development server. - Run the server project when hosting the app with ASP.NET Core. -Blazor WebAssembly apps don't support debugging using Visual Studio. To run the app, use `Ctrl+F5` instead of `F5`. You can instead debug Blazor WebAssembly apps directly in the browser. See [Debug ASP.NET Core Blazor](/aspnet/core/blazor/debug) for details. +Blazor WebAssembly apps can be debugged in both browser and Visual Studio.See [Debug ASP.NET Core Blazor WebAssembly](/aspnet/core/blazor/debug) for details. >[!div class="step-by-step"] >[Previous](hosting-models.md) diff --git a/docs/architecture/blazor-for-web-forms-developers/security-authentication-authorization.md b/docs/architecture/blazor-for-web-forms-developers/security-authentication-authorization.md index c3c4aa599d125..e3f0c472a2a17 100644 --- a/docs/architecture/blazor-for-web-forms-developers/security-authentication-authorization.md +++ b/docs/architecture/blazor-for-web-forms-developers/security-authentication-authorization.md @@ -4,27 +4,27 @@ description: Learn how to handle authentication and authorization in ASP.NET Web author: ardalis ms.author: daroth no-loc: [Blazor] -ms.date: 09/11/2019 +ms.date: 11/20/2020 --- # Security: Authentication and Authorization in ASP.NET Web Forms and Blazor -Migrating from an ASP.NET Web Forms application to Blazor will almost certainly require updating how authentication and authorization is performed, assuming the application had authentication configured. This chapter will cover how to migrate from the ASP.NET Web Forms universal provider model (for membership, roles, and user profiles) and how to work with ASP.NET Core Identity from Blazor apps. While this chapter will cover the high level steps and considerations, the detailed steps and scripts may be found in the referenced documentation. +Migrating from an ASP.NET Web Forms application to Blazor will almost certainly require updating how authentication and authorization are performed, assuming the application had authentication configured. This chapter will cover how to migrate from the ASP.NET Web Forms universal provider model (for membership, roles, and user profiles) and how to work with ASP.NET Core Identity from Blazor apps. While this chapter will cover the high-level steps and considerations, the detailed steps and scripts may be found in the referenced documentation. ## ASP.NET universal providers -Since ASP.NET 2.0, the ASP.NET Web Forms platform has supported a provider model for a variety of features, including membership. The universal membership provider, along with the optional role provider, is very commonly deployed with ASP.NET Web Forms applications. It offers a robust and secure way to manage authentication and authorization that continues to work well today. The most recent offering of these universal providers is available as a NuGet package, [Microsoft.AspNet.Providers](https://www.nuget.org/packages/Microsoft.AspNet.Providers). +Since ASP.NET 2.0, the ASP.NET Web Forms platform has supported a provider model for a variety of features, including membership. The universal membership provider, along with the optional role provider, is commonly deployed with ASP.NET Web Forms applications. It offers a robust and secure way to manage authentication and authorization that continues to work well today. The most recent offering of these universal providers is available as a NuGet package, [Microsoft.AspNet.Providers](https://www.nuget.org/packages/Microsoft.AspNet.Providers). -The Universal Providers work with a SQL database schema that includes tables like `aspnet_Applications`, `aspnet_Membership`, `aspnet_Roles`, and `aspnet_Users`. When configured by running the [aspnet_regsql.exe command](/previous-versions/ms229862(v=vs.140)), the providers install tables and stored procedures that provide all of the necessary queries and commands necessary to work with the underlying data. The database schema and these stored procedures are not compatible with newer ASP.NET Identity and ASP.NET Core Identity systems, so existing data must be migrated into the new system. Figure 1 shows an example table schema configured for universal providers. +The Universal Providers work with a SQL database schema that includes tables like `aspnet_Applications`, `aspnet_Membership`, `aspnet_Roles`, and `aspnet_Users`. When configured by running the [aspnet_regsql.exe command](/previous-versions/ms229862(v=vs.140)), the providers install tables and stored procedures that provide all of the necessary queries and commands to work with the underlying data. The database schema and these stored procedures are not compatible with newer ASP.NET Identity and ASP.NET Core Identity systems, so existing data must be migrated into the new system. Figure 1 shows an example table schema configured for universal providers. ![universal providers schema](./media/security/membership-tables.png) -The universal provider handles users, membership, roles, and profiles. Users are assigned globally unique identifiers and very basic information (userId, userName) is stored in the `aspnet_Users` table. Authentication information, such as password, password format, password salt, lockout counters and details, etc. are stored in the `aspnet_Membership` table. Roles consist simply of names and unique identifiers, which are assigned to users via the `aspnet_UsersInRoles` association table, providing a many-to-many relationship. +The universal provider handles users, membership, roles, and profiles. Users are assigned globally unique identifiers and basic information like userId, userName etc. are stored in the `aspnet_Users` table. Authentication information, such as password, password format, password salt, lockout counters and details, etc. are stored in the `aspnet_Membership` table. Roles consist simply of names and unique identifiers, which are assigned to users via the `aspnet_UsersInRoles` association table, providing a many-to-many relationship. If your existing system is using roles in addition to membership, you will need to migrate the user accounts, the associated passwords, the roles, and the role membership into ASP.NET Core Identity. You will also most likely need to update your code where you're currently performing role checks using if statements to instead leverage declarative filters, attributes, and/or tag helpers. We will review migration considerations in greater detail at the end of this chapter. ### Authorization configuration in Web Forms -To configure authorized access to certain pages in an ASP.NET Web Forms application, typically you specify that certain pages or folders are inaccessible to anonymous users. This is done in the web.config file: +To configure authorized access to certain pages in an ASP.NET Web Forms application, typically you specify that certain pages or folders are inaccessible to anonymous users. This configuration is done in the web.config file: ```xml @@ -42,7 +42,7 @@ To configure authorized access to certain pages in an ASP.NET Web Forms applicat ``` -The `authentication` configuration section sets up forms authentication for the application. The `authorization` section is used to disallow anonymous users for the entire application. However, you can provide more granular authorization rules on a per-location basis as well as apply role based authorization checks. +The `authentication` configuration section sets up the forms authentication for the application. The `authorization` section is used to disallow anonymous users for the entire application. However, you can provide more granular authorization rules on a per-location basis as well as apply role-based authorization checks. ```xml @@ -67,13 +67,13 @@ The above configuration, when combined with the first one, would allow anonymous ``` -The above configuration, when combined with the others, restricts access to the `/admin` folder and all resources within it to members of the "Administrators" role. This could also be applied by placing a separate `web.config` file within the `/admin` folder root. +The above configuration, when combined with the others, restricts access to the `/admin` folder and all resources within it to members of the "Administrators" role. This restriction could also be applied by placing a separate `web.config` file within the `/admin` folder root. ### Authorization code in Web Forms In addition to configuring access using `web.config`, you can also programmatically configure access and behavior in your Web Forms application. For instance, you can restrict the ability to perform certain operations or view certain data based on the user's role. -This code can be used both in codebehind logic as well as in the page itself: +This code can be used both in code-behind logic as well as in the page itself: ```html <% if (HttpContext.Current.User.IsInRole("Administrators")) { %> @@ -100,11 +100,11 @@ protected void Page_Load(object sender, EventArgs e) In the code above, role-based access control (RBAC) is used to determine whether certain elements of the page, such as a `SecretPanel`, are visible based on the current user's role. -Typically, ASP.NET Web Forms applications configure security within the `web.config` file and then add additional checks where needed in `.aspx` pages and their related `.aspx.cs` codebehind files. Most applications leverage the universal membership provider, frequently with the additional role provider. +Typically, ASP.NET Web Forms applications configure security within the `web.config` file and then add additional checks where needed in `.aspx` pages and their related `.aspx.cs` code-behind files. Most applications leverage the universal membership provider, frequently with the additional role provider. ## ASP.NET Core Identity -Although still tasked with authentication and authorization, ASP.NET Core Identity uses a different set of abstractions and assumptions when compared to the universal providers. For example, the new Identity model supports third party authentication, allowing users to authenticate using a social media account or other trusted authentication provider. ASP.NET Core Identity supports UI for commonly needed pages like login, logout, and register. It leverages EF Core for its data access, and uses EF Core migrations to generate the necessary schema required to supports its data model. This [introduction to Identity on ASP.NET Core](/aspnet/core/security/authentication/identity) provides a good overview of what is included with ASP.NET Core Identity and how to get started working with it. If you haven't already set up ASP.NET Core Identity in your application and its database, it will help you get started. +Although still tasked with authentication and authorization, ASP.NET Core Identity uses a different set of abstractions and assumptions when compared to the universal providers. For example, the new Identity model supports third party authentication, allowing users to authenticate using a social media account or other trusted authentication provider. ASP.NET Core Identity supports UI for commonly needed pages like login, logout, and register. It leverages EF Core for its data access, and uses EF Core migrations to generate the necessary schema required to support its data model. This [introduction to Identity on ASP.NET Core](/aspnet/core/security/authentication/identity) provides a good overview of what is included with ASP.NET Core Identity and how to get started working with it. If you haven't already set up ASP.NET Core Identity in your application and its database, it will help you get started. ### Roles, claims, and policies @@ -112,9 +112,9 @@ Both the universal providers and ASP.NET Core Identity support the concept of ro In addition to roles, ASP.NET Core identity supports the concepts of claims and policies. While a role should specifically correspond to a set of resources a user in that role should be able to access, a claim is simply part of a user's identity. A claim is a name value pair that represents what the subject is, not what the subject can do. -It is possible to directly inspect a user's claims and determine based on these whether a user should be given access to a resource. However, such checks are often repetitive and scattered throughout the system. A better approach is to define a *policy*. +It is possible to directly inspect a user's claims and determine based on these values whether a user should be given access to a resource. However, such checks are often repetitive and scattered throughout the system. A better approach is to define a *policy*. -An authorization policy consists of one or more requirements. Policies are registered as part of the authorization service configuration in the `ConfigureServices` method of `Startup.cs`. For example, the following code snippet configures a policy called "CanadiansOnly" which has the requirement that the user have the Country claim with the value of "Canada". +An authorization policy consists of one or more requirements. Policies are registered as part of the authorization service configuration in the `ConfigureServices` method of `Startup.cs`. For example, the following code snippet configures a policy called "CanadiansOnly", which has the requirement that the user has the Country claim with the value of "Canada". ```csharp services.AddAuthorization(options => @@ -125,7 +125,7 @@ services.AddAuthorization(options => You can [learn more about how to create custom policies in the documentation](/aspnet/core/security/authorization/policies). -Whether you're using policies or roles, you can specify that a particular page in your Blazor application require that role or policy with the `[Authorize]` attribute, applied with the `@attribute` directive. +Whether you're using policies or roles, you can specify that a particular page in your Blazor application requires that role or policy with the `[Authorize]` attribute, applied with the `@attribute` directive. Requiring a role: @@ -139,7 +139,7 @@ Requiring a policy be satisfied: @attribute [Authorize(Policy ="CanadiansOnly")] ``` -If you need access to a user's authentication state, roles, or claims in your code, there are two primary ways to achieve this. The first is to receive the authentication state as a cascading parameter. The second is to access the state using an injected `AuthenticationStateProvider`. The details of each of these approaches are described in the [Blazor Security documentation](/aspnet/core/blazor/security/). +If you need access to a user's authentication state, roles, or claims in your code, there are two primary ways to achieve this functionality. The first is to receive the authentication state as a cascading parameter. The second is to access the state using an injected `AuthenticationStateProvider`. The details of each of these approaches are described in the [Blazor Security documentation](/aspnet/core/blazor/security/). The following code shows how to receive the `AuthenticationState` as a cascading parameter: @@ -212,9 +212,9 @@ If you need to work with roles, follow the same approach. You may need to inject Migrating from ASP.NET Web Forms and universal providers to ASP.NET Core Identity requires several steps: -1. Create ASP.NET Core Identity database schema in destination database +1. Create ASP.NET Core Identity database schema in the destination database 2. Migrate data from universal provider schema to ASP.NET Core Identity schema -3. Migrate configuration from web.config to middleware and services, typically in `Startup.cs` +3. Migrate configuration from the `web.config` to middleware and services, typically in `Startup.cs` 4. Update individual pages using controls and conditionals to use tag helpers and new identity APIs. Each of these steps is described in detail in the following sections. @@ -233,23 +233,23 @@ Click on the "Apply Migrations" button and the necessary database tables should ![migration files](./media/security/migration-files.png) -You can run the migration yourself, without running the web application, using this command line tool: +You can run the migration yourself, without running the web application, using this command-line tool: ```powershell dotnet ef database update ``` -If you would rather run a script to apply the new schema to an existing database, you can script these migrations from the command line. Run this command to generate the script: +If you would rather run a script to apply the new schema to an existing database, you can script these migrations from the command-line. Run this command to generate the script: ```powershell dotnet ef migrations script -o auth.sql ``` -This will produce a SQL script in the output file `auth.sql` which can then be run against whatever database you like. If you have any trouble running `dotnet ef` commands, [make sure you have the EF Core tools installed on your system](/ef/core/miscellaneous/cli/dotnet). +The above command will produce a SQL script in the output file `auth.sql`, which can then be run against whatever database you like. If you have any trouble running `dotnet ef` commands, [make sure you have the EF Core tools installed on your system](/ef/core/miscellaneous/cli/dotnet). In the event you have additional columns on your source tables, you will need to identify the best location for these columns in the new schema. Generally, columns found on the `aspnet_Membership` table should be mapped to the `AspNetUsers` table. Columns on `aspnet_Roles` should be mapped to `AspNetRoles`. Any additional columns on the `aspnet_UsersInRoles` table would be added to the `AspNetUserRoles` table. -It's also worth considering putting any additional columns on separate tables, so that future migrations won't need to take into account such customizations of the default identity schema. +It's also worth considering putting any additional columns on separate tables. So that future migrations won't need to take into account such customizations of the default identity schema. ### Migrating data from universal providers to ASP.NET Core Identity @@ -261,7 +261,7 @@ It is possible to migrate user passwords but the process is much more involved. ### Migrating security settings from web.config to Startup.cs -As noted above, ASP.NET membership and role providers are configured in the application's web.config file. Since ASP.NET Core apps are not tied to IIS and use a separate system for configuration, these settings must be configured elsewhere. For the most part, ASP.NET Core Identity is configured in the `Startup.cs` file. Open the web project that was created earlier (to generate the identity table schema) and review its `Startup.cs` file. +As noted above, ASP.NET membership and role providers are configured in the application's `web.config` file. Since ASP.NET Core apps are not tied to IIS and use a separate system for configuration, these settings must be configured elsewhere. For the most part, ASP.NET Core Identity is configured in the `Startup.cs` file. Open the web project that was created earlier (to generate the identity table schema) and review its `Startup.cs` file. The default ConfigureServices method adds support for EF Core and Identity: @@ -320,19 +320,19 @@ ASP.NET Identity does not configure anonymous or role-based access to locations ### Updating individual pages to use ASP.NET Core Identity abstractions -In your ASP.NET Web Forms application, if you had web.config settings to deny access to certain pages or folders to anonymous users, you would migrate these by simply adding the `[Authorize]` attribute to such pages: +In your ASP.NET Web Forms application, if you had `web.config` settings to deny access to certain pages or folders to anonymous users, you would migrate these changes by adding the `[Authorize]` attribute to such pages: ```razor @attribute [Authorize] ``` -If you further had denied access except to those users belonging to a certain role, you would likewise migrate this by adding an attribute specifying a role: +If you further had denied access except to those users belonging to a certain role, you would likewise migrate this behavior by adding an attribute specifying a role: ```razor @attribute [Authorize(Roles ="administrators")] ``` -Note that the `[Authorize]` attribute only works on `@page` components that are reached via the Blazor Router. The attribute does not work with child components, which should instead use `AuthorizeView`. +The `[Authorize]` attribute only works on `@page` components that are reached via the Blazor Router. The attribute does not work with child components, which should instead use `AuthorizeView`. If you have logic within page markup for determining whether to display some code to a certain user, you can replace this with the `AuthorizeView` component. The [AuthorizeView component](/aspnet/core/blazor/security#authorizeview-component) selectively displays UI depending on whether the user is authorized to see it. It also exposes a `context` variable that can be used to access user information. @@ -349,7 +349,7 @@ If you have logic within page markup for determining whether to display some cod ``` -You can access authentication state within procedural logic by accessing the user from a `Task @@ -405,7 +405,7 @@ The `AuthenticationState` does first need to be setup as a cascading value befor ## Summary -Blazor uses the same security model as ASP.NET Core, which is ASP.NET Core Identity. Migrating from universal providers to ASP.NET Core Identity is relatively straightforward, assuming not too much customization was applied to the original data schema. Once the data has been migrated, working with authentication and authorization in Blazor apps is well-documented, with configurable as well as programmatic support for most security requirements. +Blazor uses the same security model as ASP.NET Core, which is ASP.NET Core Identity. Migrating from universal providers to ASP.NET Core Identity is relatively straightforward, assuming not too much customization was applied to the original data schema. Once the data has been migrated, working with authentication and authorization in Blazor apps is well documented, with configurable as well as programmatic support for most security requirements. ## References From fc720bbaf977c6571f912d38148d267045a9e256 Mon Sep 17 00:00:00 2001 From: Sumit Ghosh <13281246+sughosneo@users.noreply.github.com> Date: Thu, 19 Nov 2020 11:22:14 +0530 Subject: [PATCH 2/3] Fixed lint error in project-structure file. --- .../blazor-for-web-forms-developers/project-structure.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/architecture/blazor-for-web-forms-developers/project-structure.md b/docs/architecture/blazor-for-web-forms-developers/project-structure.md index 442c3ca40cd1d..8287a80822d2c 100644 --- a/docs/architecture/blazor-for-web-forms-developers/project-structure.md +++ b/docs/architecture/blazor-for-web-forms-developers/project-structure.md @@ -46,7 +46,7 @@ The project file for a Blazor WebAssembly app looks slightly more involved (exac Blazor WebAssembly project targets `Microsoft.NET.Sdk.BlazorWebAssembly` instead of `Microsoft.NET.Sdk.Web` sdk because they run in the browser on a WebAssembly-based .NET runtime. You can't install .NET into a web browser like you can on a server or developer machine. Consequently, the project references the Blazor framework using individual package references. -By comparison, a default ASP.NET Web Forms project includes almost 300 lines of XML in its *.csproj* file, most of which is explicitly listing the various code and content files in the project. With the release of `.NET 5` both `Blazor Server` and `Blazor WebAssembly` app can easily share one unified runtime. +By comparison, a default ASP.NET Web Forms project includes almost 300 lines of XML in its *.csproj* file, most of which is explicitly listing the various code and content files in the project. With the release of `.NET 5` both `Blazor Server` and `Blazor WebAssembly` app can easily share one unified runtime. Although they're supported, individual assembly references are less common in .NET projects. Most project dependencies are handled as NuGet package references. You only need to reference top-level package dependencies in .NET projects. Transitive dependencies are included automatically. Instead of using the *packages.config* file commonly found in ASP.NET Web Forms projects to reference packages, package references are added to the project file using the `` element. From 2bc74c9b042175cbb92fa1d0ab814896ba6dd37d Mon Sep 17 00:00:00 2001 From: Sumit Ghosh <13281246+sughosneo@users.noreply.github.com> Date: Tue, 1 Dec 2020 17:29:47 +0530 Subject: [PATCH 3/3] Updated index page. --- .../blazor-for-web-forms-developers/index.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/architecture/blazor-for-web-forms-developers/index.md b/docs/architecture/blazor-for-web-forms-developers/index.md index 372f75f89930a..fcbde42c63c54 100644 --- a/docs/architecture/blazor-for-web-forms-developers/index.md +++ b/docs/architecture/blazor-for-web-forms-developers/index.md @@ -4,7 +4,7 @@ description: Learn how to build full-stack web apps with .NET using Blazor and . author: danroth27 ms.author: daroth no-loc: [Blazor, WebAssembly] -ms.date: 09/11/2019 +ms.date: 12/01/2020 --- # Blazor for ASP.NET Web Forms Developers @@ -12,6 +12,10 @@ ms.date: 09/11/2019 > DOWNLOAD available at: +**EDITION v1.0** + +Refer [changelog](https://aka.ms/blazor-ebook-changelog) for the book updates and community contributions. + PUBLISHED BY Microsoft Developer Division, .NET, and Visual Studio product teams @@ -26,7 +30,7 @@ Copyright © 2020 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. -This book is provided "as-is" and expresses the author's views and opinions. The views, opinions and information expressed in this book, including URL and other Internet website references, may change without notice. +This book is provided "as-is" and expresses the author's views and opinions. The views, opinions, and information expressed in this book, including URL and other Internet website references, may change without notice. Some examples depicted herein are provided for illustration only and are fictitious. No real association or connection is intended or should be inferred. @@ -52,7 +56,7 @@ Authors: .NET has long supported web app development through ASP.NET, a comprehensive set of frameworks and tools for building any kind of web app. ASP.NET has its own lineage of web frameworks and technologies starting all the way back with classic Active Server Pages (ASP). Frameworks like ASP.NET Web Forms, ASP.NET MVC, ASP.NET Web Pages, and more recently ASP.NET Core, provide a productive and powerful way to build *server-rendered* web apps, where UI content is dynamically generated on the server in response to HTTP requests. Each ASP.NET framework caters to a different audience and app building philosophy. ASP.NET Web Forms shipped with the original release of the .NET Framework and enabled web development using many of the patterns familiar to desktop developers, like reusable UI controls with simple event handling. However, none of the ASP.NET offerings provide a way to run code that executed in the user's browser. To do that requires writing JavaScript and using any of the many JavaScript frameworks and tools that have phased in and out of popularity over the years: jQuery, Knockout, Angular, React, and so on. -[Blazor](https://blazor.net) is a new web framework that changes what is possible when building web apps with .NET. Blazor is a client-side web UI framework based on C# instead of JavaScript. With Blazor you can write your client-side logic and UI components in C#, compile them into normal .NET assemblies, and then run them directly in the browser using a new open web standard called WebAssembly. Or alternatively, Blazor can run your .NET UI components on the server and handle all UI interactions fluidly over a real-time connection with the browser. When paired with .NET running on the server, Blazor enables full-stack web development with .NET. While Blazor shares many commonalities with ASP.NET Web Forms, like having a reusable component model and a simple way to handle user events, it also builds on the foundations of .NET Core to provide a modern and high performance web development experience. +[Blazor](https://blazor.net) is a new web framework that changes what is possible when building web apps with .NET. Blazor is a client-side web UI framework based on C# instead of JavaScript. With Blazor you can write your client-side logic and UI components in C#, compile them into normal .NET assemblies, and then run them directly in the browser using a new open web standard called WebAssembly. Or alternatively, Blazor can run your .NET UI components on the server and handle all UI interactions fluidly over a real-time connection with the browser. When paired with .NET running on the server, Blazor enables full-stack web development with .NET. While Blazor shares many commonalities with ASP.NET Web Forms, like having a reusable component model and a simple way to handle user events, it also builds on the foundations of .NET to provide a modern and high-performance web development experience. This book introduces ASP.NET Web Forms developers to Blazor in a way that is familiar and convenient. It introduces Blazor concepts in parallel with analogous concepts in ASP.NET Web Forms while also explaining new concepts that may be less familiar. It covers a broad range of topics and concerns including component authoring, routing, layout, configuration, and security. And while the content of this book is primarily for enabling new development, it also covers guidelines and strategies for migrating existing ASP.NET Web Forms to Blazor for when you want to modernize an existing app.