Introduction
Having set up forms authentication for my little project (which is still on github) I found the need to put a login/logout link/thing on my viewpages.
Since I could not immediately find how to this I asked on the
The view
In essence it is very simple to make the login/logout link since you are able to use the Nancy context in your view.
All you need is this.
xml
@If Url.RenderContext.Context.CurrentUser Is Nothing Then
@<a href="/login">Login</a>
Else
@Url.RenderContext.Context.CurrentUser.UserName
@<a href="/logout">Logout</a>
End If
When a user is not logged in (sometimes also known as logged out) the login link will appear which will guide you to the loginpage. Once the user is logged in we will show his username and the logout link so he can press that and be amazed.
The VB razor syntax was kind of hard to figure out but nothing a little trail and error won’t fix.
And then you go and try this and notice the nice errormessage you will get.
With this in the details view.
Error Details
Error compiling template: Views/Master.vbhtml
Errors:
[BC30652] Line: 8 Column: 0 – Reference required to assembly ‘Nancy, Version=0.14.1.0, Culture=neutral, PublicKeyToken=null’ containing the type ‘Nancy.ViewEngines.IRenderContext’. Add one to your project. (show)
[BC30652] Line: 11 Column: 0 – Reference required to assembly ‘Nancy, Version=0.14.1.0, Culture=neutral, PublicKeyToken=null’ containing the type ‘Nancy.ViewEngines.IRenderContext’. Add one to your project. (show)
Details:
@RenderBody()