'How do I hide login view after a condition?
I want to restrict a view after a user login into system.
Example: I have a register view. After a user login into system I want to block access to register view. Because we don't need to view this view. How can I do that?
Solution 1:[1]
You need store the login infomation in session or cookie, then you can get it. In your register page method, you can read the login info and decide which page to choose.
public IActionResult registerView(){
// you can set login info in session or another better ways
var isLogin=HttpContext.Session.GetString("isLogin");
if(isLogin==null || isLogin==""){
return View();
}else{
return RedirectToAction(nameof(Index));
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jason |
