首页 > 解决方案 > 如何在 ASP.NET MVC 中使用隐藏的 csrf-token 登录

问题描述

我有一个带有以下字段的外部网站的登录表单链接,有用户名、密码和术语字段可见,还有一个隐藏字段是 _token (csrf-token)。如何在单击我当前网站的按钮时自动登录该外部网站。

每次收到响应 419 Page Expired 时,我都尝试了很多解决方案。我当前的网站在 ASP.NET MVC 5 C#

<form id="login" class="login" target="_blank" method="post" action="https://test.com/login">
      <input type="hidden" name="_token" value="qwewqewqewqewqewqewq">
        <input id="username" name="username" value="" />
        <input id="password" type="password" name="password" value="" />
        <input id="terms" type="checkbox" name="terms" checked />
        <button type="submit"></button>
    </form>

标签: c#asp.net-mvccsrfautologincsrf-token

解决方案


推荐阅读