"fix" code sample (#4061)

* "fix" code sample

* Update views.md

* Update views.md
pull/4114/head
Steven Moschidis 2017-08-25 22:01:21 +01:00 committed by Rick Anderson
parent fa4fc02626
commit 74e22e08e3
1 changed files with 14 additions and 1 deletions

View File

@ -29,14 +29,27 @@ Once you have injected the authorization service you use it by calling the `Auth
In some cases the resource will be your view model, and you can call `AuthorizeAsync` in exactly the same way as you would check during [resource based authorization](resourcebased.md#security-authorization-resource-based-imperative);
# [ASP.NET Core 2.x](#tab/aspnetcore2x)
```csharp
@if (await AuthorizationService.AuthorizeAsync(User, Model, Operations.Edit))
@if ((await AuthorizationService.AuthorizeAsync(User, Model, Operations.Edit)).Succeeded)
{
<p><a class="btn btn-default" role="button"
href="@Url.Action("Edit", "Document", new { id = Model.Id })">Edit</a></p>
}
```
# [ASP.NET Core 1.x](#tab/aspnetcore1x)
```csharp
@if (await AuthorizationService.AuthorizeAsync(User, Model, Operations.Edit))
{
<p><a class="btn btn-default" role="button"
href="@Url.Action("Edit", "Document", new { id = Model.Id })">Edit</a></p>
}
```
---
Here you can see the model is passed as the resource authorization should take into consideration.
>[!WARNING]