My project was rebuilt into folders called "area", everything worked before and the user was authorized to the account management panel. After adding these areas, the project cannot see where it should go.
My structure project:
Structure in Area "Authorize":
I tried to work with a route for areas in Startup.cs:
...
services.AddMvc( options =>
options.EnableEndpointRouting = false)
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
...
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapAreaRoute(
name: "MyAreaAuthorize",
areaName: "Authorize",
template: "Authorize/{controller=Account}/{action=Index}/{id?}");
routes.MapAreaRoute(
name: "MyAreaManage",
areaName: "Authorize",
template: "Authorize/{controller=Manage}/{action=Index}/{id?}");
routes.MapAreaRoute(
name: "MyAreaAdminAccount",
areaName: "AdminAccount",
template: "AdminAccount/{controller=Admin}/{action=Index}/{id?}");
});
I also copied _ViewImports.cshtml to folders with views for each area.
My file looks like this:
@using Example
@using Example.Models
@using Example.AccountArea.Models
@using Microsoft.AspNetCore.Identity
@addTagHelper Example.TagHelpers.*, Example
@addTagHelper Identity.TagHelpers.*, Identity
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
View in Area "Authorize":
@using Example.AccountArea.Models;
@using Microsoft.AspNetCore.Identity;
@model Example.AccountArea.Models.AccountModel.LoginModel;
@inject SignInManager<UserApp> Sign
@{
ViewData["Title"] = "Zaloguj się";
}
<form asp-area="Authorize" asp-controller="Account" asp-action="Login" method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div>
<input asp-for="Email" placeholder="Email" />
<span asp-validation-for="Email" class="text-danger margin-text-form"></span>
</div>
<div>
<input asp-for="Password" placeholder="Hasło" />
<span asp-validation-for="Password" class="text-danger margin-text-form"></span>
</div>
<div class="group">
<div class="checkbox">
<input type='checkbox' id='my-checkbox'>
<label for='my-checkbox'>@Html.DisplayNameFor(m => m.RememberMe)</label>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn-dark">Login</button>
</div>
<div class="group">
<p>
<a asp-area="Authorize" asp-controller="Account" asp-action="ForgotPassword">Forgot?</a>
</p>
<p>
<a asp-controller="Account" asp-action="Register">Register</a>
</p>
</div>
</form>
</section>
</div>
@section Scripts {
<partial name="_ValidationScriptsPartial" />
}
Controller Account in Area "Authorize:
The controller has included info for the class that it belongs to the "Authorize" area
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Authentication;
using System;
using Example.AccountArea.Models;
using Example.AccountArea.Models.AccountModel;
namespace Example.AccountArea.Controllers
{
[Area("Authorize")]
public class AccountController : Controller
{
...My code is irrelevant to the problem...
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> Login()
{
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginModel login)
{
if (ModelState.IsValid)
{
var result = await _signInManager.PasswordSignInAsync(login.Email, login.Password, login.RememberMe, false);
if (result.Succeeded)
{
_logger.LogInformation("...");
return RedirectToAction(nameof(ManageController.Index), "Manage");
}
if (result.IsLockedOut)
{
_logger.LogWarning("...");
return RedirectToAction(nameof(LockoutOptions));
}
else
{
ModelState.AddModelError(string.Empty, "...");
return View("../Home/Index");
}
}
// If we got this far, something failed, redisplay form
return View("../Home/Index", login);
}
...My code is irrelevant to the problem...
}
}
After starting the application, the login form is displayed to me, the links do not work, the message is similar to the one below, it does not pass data validation and after clicking "Log in" it displays:
Physical transition of pages on the browser:
From login:
To:
Please do not inform me that it is copied from and there are similar solutions because I tried to find solutions in other similar posts first!
Any ideas ? Thank you if you help me..