Last post Jul 23, 2016 05:06 AM by anishpsla
Jul 22, 2016 05:57 PM|anishpsla|LINK
I am new to asp.net core. I have moderate experience in C# and WPF. I have some experience with PHP MVC (Phalcon PHP).
I am trying to develop a new application using VS2015 community and host on Azure. I am really new to new type of authentication introduced in ASP.NET core. I do some search on BIng and got the code.
public IActionResult authorise()
if(Request.Form["username"]=="admin" && Request.Form["password"]=="admin")
var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Name, Request.Form["username"]));
claims.Add(new Claim(ClaimTypes.Role, "Admin"));
var identity = new ClaimsIdentity(claims, AuthenticationTypes.Password);
var claimsPrincipal = new ClaimsPrincipal(identity);
// Set current principal
Thread.CurrentPrincipal = claimsPrincipal;
GlobalClass.uname = Thread.CurrentPrincipal.Identity.Name.ToString();
It just a preliminary code and need many optimization. The problem is, I want to put a logout drop down in master page (_Layout.cshtml). I know
have the authenticated username. But where to put it to get username on every time I access any page. At present, I will get the usename only after authentication. But the code does not ask to authentication every time I try to open the index (It's a good
feature, and I need it).
Jul 23, 2016 02:52 AM|anurajp|LINK
You can do something like this.
@if(Context.User.Identities.Any(i => i.IsAuthenticated))
<li><a href="/Home/SignIn">Sign In</a></li>
Jul 23, 2016 05:06 AM|anishpsla|LINK
Thanks, it works. Actually, I only need
Rest of the things will done [Authorise] attribute.