Merge branch 'master' of http://github.com/aspnet/docs
commit
07a4dff1b9
|
@ -133,7 +133,7 @@ You configure options using the :dn:method:`~Microsoft.Extensions.DependencyInje
|
|||
:language: c#
|
||||
:lines: 26-42
|
||||
:dedent: 8
|
||||
:emphasize-lines: 7-10,13
|
||||
:emphasize-lines: 7,10-13
|
||||
|
||||
When you bind options to configuration, each property in your options type is bound to a configuration key of the form ``property:subproperty:...``. For example, the ``MyOptions.Option1`` property is bound to the key ``Option1``, which is read from the ``option1`` property in *appsettings.json*. Note that configuration keys are case insensitive.
|
||||
|
||||
|
|
|
@ -28,15 +28,15 @@ namespace UsingOptions
|
|||
// Setup options with DI
|
||||
services.AddOptions();
|
||||
|
||||
// Configure MyOptions using config by installing Microsoft.Extensions.Options.ConfigurationExtensions
|
||||
services.Configure<MyOptions>(Configuration);
|
||||
|
||||
// Configure MyOptions using code
|
||||
services.Configure<MyOptions>(myOptions =>
|
||||
{
|
||||
myOptions.Option1 = "value1_from_action";
|
||||
});
|
||||
|
||||
// Configure MyOptions using config by installing Microsoft.Extensions.Options.ConfigurationExtensions
|
||||
services.Configure<MyOptions>(Configuration);
|
||||
|
||||
// Add framework services.
|
||||
services.AddMvc();
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ By default, this middleware adds very simple, text-only handlers for common stat
|
|||
|
||||
.. image:: error-handling/_static/default-404-status-code.png
|
||||
|
||||
The middleware supports several different extension methods. You can pass it a custom lamba expression:
|
||||
The middleware supports several different extension methods. You can pass it a custom lamdba expression:
|
||||
|
||||
.. code-block:: c#
|
||||
|
||||
|
@ -155,4 +155,4 @@ Handling Model State Errors
|
|||
|
||||
:doc:`Model validation </mvc/models/validation>` occurs prior to each controller action being invoked, and it is the action method’s responsibility to inspect ``ModelState.IsValid`` and react appropriately. In many cases, the appropriate reaction is to return some kind of error response, ideally detailing the reason why model validation failed.
|
||||
|
||||
Some apps will choose to follow a standard convention for dealing with model validation errors, in which case a :doc:`filter </mvc/controllers/filters>` may be an appropriate place to implement such a policy. You should test how your actions behave with valid and invalid model states (learn more about :doc:`testing controller logic </mvc/controllers/testing>`).
|
||||
Some apps will choose to follow a standard convention for dealing with model validation errors, in which case a :doc:`filter </mvc/controllers/filters>` may be an appropriate place to implement such a policy. You should test how your actions behave with valid and invalid model states (learn more about :doc:`testing controller logic </mvc/controllers/testing>`).
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
:version: 1.0.0-rc1
|
||||
|
||||
.. _application-startup:
|
||||
|
||||
Application Startup
|
||||
|
|
|
@ -10,7 +10,7 @@ ASP.NET Core provides cookie :ref:`middleware <fundamentals-middleware>` which s
|
|||
Adding and configuring
|
||||
----------------------
|
||||
|
||||
The first step is adding the cookie middleware to your application. First use nuget to add the ``Microsoft.AspNetCore.Authentication.Cookies`` package. Then add the following lines to the ``Configure`` method in your *Startup.cs* file;
|
||||
The first step is adding the cookie middleware to your application. First use nuget to add the ``Microsoft.AspNetCore.Authentication.Cookies`` package. Then add the following lines to the ``Configure`` method in your *Startup.cs* file before the ``app.UseMvc()`` statement;
|
||||
|
||||
.. code-block:: c#
|
||||
|
||||
|
|
Loading…
Reference in New Issue