Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dfda48a

Browse files
Added logout in asp.net core
1 parent 2b3c4b0 commit dfda48a

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

‎Webgentle.BookStore/Webgentle.BookStore/Controllers/AccountController.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,12 @@ public async Task<IActionResult> Login(SignInModel signInModel)
7272

7373
return View(signInModel);
7474
}
75+
76+
[Route("logout")]
77+
public async Task<IActionResult> Logout()
78+
{
79+
await _accountRepository.SignOutAsync();
80+
return RedirectToAction("Index", "Home");
81+
}
7582
}
7683
}

‎Webgentle.BookStore/Webgentle.BookStore/Repository/AccountRepository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,10 @@ public async Task<SignInResult> PasswordSignInAsync(SignInModel signInModel)
3636
{
3737
return await _signInManager.PasswordSignInAsync(signInModel.Email, signInModel.Password, signInModel.RememberMe, false);
3838
}
39+
40+
public async Task SignOutAsync()
41+
{
42+
await _signInManager.SignOutAsync();
43+
}
3944
}
4045
}

‎Webgentle.BookStore/Webgentle.BookStore/Repository/IAccountRepository.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ public interface IAccountRepository
99
Task<IdentityResult> CreateUserAsync(SignUpUserModel userModel);
1010

1111
Task<SignInResult> PasswordSignInAsync(SignInModel signInModel);
12+
13+
Task SignOutAsync();
1214
}
1315
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
@inject Microsoft.AspNetCore.Identity.SignInManager<ApplicationUser> _signInManager
3+
4+
@if (_signInManager.IsSignedIn(User))
5+
{
6+
<li class="nav-item dropdown">
7+
<a class="nav-link dropdown-toggle text-dark" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
8+
Hello @User.Identity.Name
9+
</a>
10+
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
11+
<a class="dropdown-item" asp-action="Logout" asp-controller="Account">Logout</a>
12+
</div>
13+
</li>
14+
}
15+
else
16+
{
17+
<li class="nav-item">
18+
<a class="btn btn-outline-primary" asp-controller="Account" asp-action="Login">Login</a>
19+
<a class="btn btn-primary" asp-controller="Account" asp-action="Signup">Register</a>
20+
</li>
21+
}
22+
23+

‎Webgentle.BookStore/Webgentle.BookStore/Views/Shared/_header.cshtml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
</button>
2020
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
2121
<ul class="navbar-nav">
22-
<li class="nav-item">
23-
<a class="btn btn-outline-primary" asp-controller="Account" asp-action="Login">Login</a>
24-
<a class="btn btn-primary" asp-controller="Account" asp-action="Signup">Register</a>
25-
</li>
22+
<partial name="_LoginInfo" />
2623
</ul>
2724
<ul class="navbar-nav flex-grow-1">
2825
<li class="nav-item">

‎Webgentle.BookStore/Webgentle.BookStore/Webgentle.BookStore.csproj.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<WebStackScaffolding_IsAsyncSelected>False</WebStackScaffolding_IsAsyncSelected>
1515
<WebStackScaffolding_ViewDialogWidth>600</WebStackScaffolding_ViewDialogWidth>
1616
<ShowAllFiles>false</ShowAllFiles>
17-
<View_SelectedScaffolderID>RazorViewScaffolder</View_SelectedScaffolderID>
17+
<View_SelectedScaffolderID>RazorViewEmptyScaffolder</View_SelectedScaffolderID>
1818
<View_SelectedScaffolderCategoryPath>root/View</View_SelectedScaffolderCategoryPath>
1919
</PropertyGroup>
2020
</Project>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /