0
'
    namespace AspWebAppTest.Controllers
    {
       public class AccountController : Controller
        {
            public IActionResult Index()
            {
                return View();
            }
    [HttpGet]
    public IActionResult Login(string userName, string password)
    {
        if (!string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(password))
        {
            return RedirectToAction("Login");
        }

        //Check the user name and password  
        //Here can be implemented checking logic from the database  

        if (userName == "Admin" && password == "pass")
        {

            //Create the identity for the user  
            var identity = new ClaimsIdentity(new[] {
                new Claim(ClaimTypes.Name, userName)
            }, CookieAuthenticationDefaults.AuthenticationScheme);

            var principal = new ClaimsPrincipal(identity);

            var login = HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);

            return RedirectToAction("Mapping","Config");
        }

        return View();
    }

}

我有这个 Cookie 身份验证控制器,我想在用户单击“映射”选项卡和“配置”选项卡时创建一个身份验证。最初我使用的是 [HttpPost] 方法,但出现 HTTP405 错误。因此,我将 [HttpPost] 切换为 [HttpGet] 并得到了我想要的结果。这是一个图像。 在此处输入图像描述

输入正确的密码和用户名后,我收到另一个 HTTP405 错误。

这是我的配置 HTML 代码:

    @*@model ConfigMappingModel*@
    @{
        ViewData["Title"] = "Configuration";
     }

    @if (User.Identity.IsAuthenticated)
    {

<div class="jumbotron" id="third" style="        background: #2E8BC0; position: relative; opacity: .95;">

    <h1 style="font-size:45px; font-weight: bold; text-align: center;"><span class="badge badge-info">@ViewData["Title"]</span></h1>


    <div style="display:flex;">
        <a href="https://miplant-inductotherm.com" title="Miplant website link">   <img class="card-img-top" style="width: 15rem;" src="~/Mi.png" alt="Card image cap"></a>
        <img style="width: 10rem; margin-left: auto;" src="~/configuration.png" />
    </div>




    <br />


    @using (Html.BeginForm("DownloadConfig", "Home", FormMethod.Post))
    {
        <button type="submit" class="btn btn-success" style="font-size:larger; font-weight:bolder;">Download Config</button>
    }

    <br />

    @using (Html.BeginForm("UploadConfig", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        <input type="file" name="uploadFile" class="btn btn-success" />
        <button type="submit" class="btn btn-success" style="font-size:larger; font-weight:bolder;">Upload Config</button>
    }

    <br />

    <p style="color: #FF8300; font-size:larger; font-weight:bolder;">This page will display <a href="Index"><span class="badge badge-info">M<span style="color: red">i</span>Plant <span style="color: #FF8300">Gateway</span></span></a> Configuration below:</p>


    <div class="d-block p-2 bg-dark text-white rounded border border-success" style="position:relative;">
        @*@(Model.configtext)*@
        <text style="color: white;  font-size:larger; font-weight:bolder;">@Html.Raw(Model.configtext)</text>

        @*<p style="color: #FF8300;">This page is under Construction!.</p>*@
    </div>
</div>
    }

在此处输入图像描述

4

0 回答 0