Code highlighting
This commit is contained in:
parent
da60856dee
commit
33adeef6c5
|
@ -87,6 +87,7 @@ And the OWIN-Code to specify the on-premise authentication is in Startup.Auth.cs
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
# Configure the On-Premise Identity Server (Job for IT) #
|
# Configure the On-Premise Identity Server (Job for IT) #
|
||||||
|
|
||||||
|
@ -151,7 +152,7 @@ You may create a controller with the Authorize attribute like this:
|
||||||
public class RoleController : Controller
|
public class RoleController : Controller
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
The **Authorize** attribute forces the user to be logged in before any requests are routed to this controller. The log in dialog will be opened automatically if necessary.
|
The **Authorize** attribute forces the user to be logged in before any requests are routed to this controller. The log in dialog will be opened automatically if necessary.
|
||||||
|
|
||||||
|
@ -168,12 +169,13 @@ Once inside a controller (or method) requiring authorization, you have access to
|
||||||
{
|
{
|
||||||
// do something else
|
// do something else
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Within a cshtml file, you may also want to react to user membership in a certain role. One way to do this is to bind the cshtml file to a model class which contains the necessary boolean flags. Set those flags in the controller, e.g.:
|
Within a cshtml file, you may also want to react to user membership in a certain role. One way to do this is to bind the cshtml file to a model class which contains the necessary boolean flags. Set those flags in the controller, e.g.:
|
||||||
|
|
||||||
``` csharp
|
``` csharp
|
||||||
model.IsArchitect = User.IsInRole("_Architects");
|
model.IsArchitect = User.IsInRole("_Architects");
|
||||||
|
```
|
||||||
|
|
||||||
Pass the model instance to the view, then evaluate those flags in the cshtml file:
|
Pass the model instance to the view, then evaluate those flags in the cshtml file:
|
||||||
|
|
||||||
|
@ -190,5 +192,6 @@ Pass the model instance to the view, then evaluate those flags in the cshtml fil
|
||||||
<text><b>No, you are not in the Architect group.</b></text>
|
<text><b>No, you are not in the Architect group.</b></text>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Instead of using flags within the data binding model, it may be easier to have the controller just assign a property to the ViewBag and evaluate the ViewBag in the cshtml file.
|
Instead of using flags within the data binding model, it may be easier to have the controller just assign a property to the ViewBag and evaluate the ViewBag in the cshtml file.
|
||||||
|
|
Loading…
Reference in a new issue