社区首页 >问答首页 >ASP.NET MVC:不存在所需的防伪表单字段“__RequestVerificationToken”。

ASP.NET MVC:不存在所需的防伪表单字段“__RequestVerificationToken”。
EN

Stack Overflow用户
提问于 2016-04-06 13:13:25
回答 1查看 868关注 0票数 0

当生成我的代码时出现以下错误:所需的反伪造表单字段“__RequestVerificationToken”不存在

这是控制器方法:

代码语言:javascript
代码运行次数:0
复制
[HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Register(RegisterViewModel1 model)
        {
            if (ModelState.IsValid)
            {
                int month = DateTime.ParseExact(model.BirthMonth.ToString(), "MMMM", CultureInfo.CurrentCulture).Month;
                DateTime birthDate = new DateTime(model.BirthYear, month, model.BirthDay);
                var user = new ApplicationUser { Email = model.Email, UserName = model.UserName, Name = model.Name, Surname = model.Surname, BirthDate = birthDate, Country = model.Country, PhoneNumber = model.PhoneNumber };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    db.Users.Add(user);

                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    var users = db.Users.ToList();
                    var adminUsers = db.Users.Where(u => u.IsAdmin == true).ToList();

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);

//视图

代码语言:javascript
代码运行次数:0
复制
@model GAPT.Models.RegisterViewModel1
@{
    ViewBag.Title = "Tours-Maltin";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div id="content">
    <div class="container">
        <div class="row">
            <div class="col-md-6">

                    @Html.AntiForgeryToken()
                    <form action="@Url.Action("Register","Account")" method="post">
                        @*"Index","Home"*@
                        <div class="form-group" style="width:280px">
                            @*<label for="name-login">Surname <p style="color:red; display:inline"> *</p></label>
                            <input type="text" class="form-control" id="name-login" required>*@
                            @Html.LabelFor(m => m.Name, new { @class = "col-md-2 control-label" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
                            </div>
                        </div>
                        <div class="form-group" style="width:280px">
                            @*<label for="surname-login">Surname <p style="color:red; display:inline"> *</p></label>
                            <input type="text" class="form-control" id="surname-register" required>*@
                            @Html.LabelFor(m => m.Surname, new { @class = "col-md-2 control-label" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(m => m.Surname, new { @class = "form-control" })
                            </div>
                        </div>
                        <div class="form-group">
                            @*<label for="email-login">Email <p style="color:red; display:inline"> *</p></label>
                            <input type="email" class="form-control" id="email-login" required>*@
                            @Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
                            </div>
                        </div>
                        <div class="form-group">
                            <script>
                            </script>
                            <label for="dob-login" style="display:block;">Date of Birth <p style="color:red; display:inline"> *</p></label>
                            <select name="BirthDay" id="BirthDay" onchange="runDay()" style="width:91px;height:34px;font-size:14px; text-align:center" required>
                                <option value=""> - Day - </option>
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                                <option value="7">7</option>
                                <option value="8">8</option>
                                <option value="9">9</option>
                                <option value="10">10</option>
                                <option value="11">11</option>
                            </select>
                            <select name="BirthMonth" id="BirthMonth" onchange="runMonth()" style="width:91px;height:34px;font-size:14px;text-align:center" required>
                                <option value=""> - Month - </option>
                                <option value="January">January</option>
                                <option value="Febuary">Febuary</option>
                                <option value="March">March</option>
                                <option value="April">April</option>
                                <option value="May">May</option>
                                <option value="June">June</option>
                                <option value="July">July</option>
                                <option value="August">August</option>
                            </select>
                            <select name="BirthYear" id="BirthYear" onchange="runYear()" style="width:91px; height:34px;font-size:14px; text-align:center" required>
                                <option value=""> - Year - </option>
                                <option value="2000">2000</option>
                                <option value="1999">1999</option>
                                <option value="1998">1998</option>
                                <option value="1997">1997</option>
                                <option value="1996">1996</option>
                                <option value="1995">1995</option>
                                <option value="1994">1994</option>
                                <option value="1993">1993</option>
                                <option value="1992">1992</option>
                                <option value="1991">1991</option>
                                <option value="1990">1990</option>
                                <option value="1989">1989</option>
                                <option value="1988">1988</option>
                                <option value="1987">1987</option>
                                <option value="1986">1986</option>
                                <option value="1985">1985</option>
                                <option value="1984">1984</option>
                                <option value="1983">1983</option>
                            </select>

                            <script>
                                function runDay() {
                                    //if (document.getElementById("srt").value != "") {
                                    var day = document.getElementById("Day").value;
                                    document.getElementById("BirthDay").value = day;
                                    //}
                                }
                            </script>

                            <script>
                                function runMonth() {
                                    //if (document.getElementById("srt").value != "") {
                                    var month = document.getElementById("BirthMonth").value;
                                    document.getElementById("BirthMonth").value = month;
                                    //}
                                }
                            </script>
                            @*@Html.DropDownListFor(m => m., month: month, htmlAttributes: new { @class = "BirthMonth" })*@

                            <script>
                                function runYear() {
                                    //if (document.getElementById("srt").value != "") {
                                    var year = document.getElementById("Year").value;
                                    document.getElementById("BirthYear").value = year;
                                    //}
                                }
                            </script>
                        </div>

                        <div class="form-group">
                            @*<label for="select-country" style="display:block;">Country <p style="color:red; display:inline"> *</p></label>
                            <input type="text" id="country" class="form-control" style="padding-right:25%;text-align:center;padding-left:25%;">*@
                            @Html.LabelFor(m => m.Country, new { @class = "col-md-2 control-label", @id="country"})
                            <div class="col-md-10">
                                @Html.TextBoxFor(m => m.Country, new { @class = "form-control" })
                            </div>

                            <!--problem-->
                            <!--<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>-->

                            <script src="~/Scripts/countrySelect.min.js"></script>
                            <script>
                                $("#country").countrySelect();
                            </script>
                        </div>

                        <div class="form-group">
                            @*<label for="username-login">Username<p style="color:red; display:inline"> *</p></label>
                            <input type="text" pattern='^(?=.{6,20}$)(?!.*[._-]{2})[a-z][a-z0-9._-]*[a-z0-9]$' title="Username needs to be between 6 to 20 characters and can only contain alphanumeric characters, _ . or - which cannot be used near each other" class="form-control"  id="username-login" required>*@
                            @Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
                            </div>
                        </div>
                        <div class="form-group">
                            @*<label for="mobile-login" style="text-wrap:normal">Mobile Number - So we can send you important information and reminders about your tours <p style="color:red; display:inline"> *</p></label>
                            <input type="tel" class="form-control" id="phone" style="padding-right: 26.7%;" required>*@
                            @Html.LabelFor(m => m.PhoneNumber, new { @class = "col-md-2 control-label" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(m => m.PhoneNumber, new { @class = "form-control", id = "mobile" })
                            </div>
                        </div>
                        <div class="form-group">
                            @*<label for="password-login">Password <p style="color:red; display:inline"> *</p></label>
                            <input type="password"  pattern='^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!#"$%()^&*_=+-]).{8,16}$' title='Password needs to be between 8 to 20 characters and must include alphanumeric characters. Special characters accepted _ - . which must not be near each other.' class="form-control" id="password-login" required>*@
                            @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
                            <div class="col-md-10">
                                @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
                            </div>
                        </div>
                        <div class="form-group">
                            @*<label for="confirm-password-login">Confirm Password <p style="color:red; display:inline"> *</p></label>
                            <input type="password" class="form-control" id="confirm-password-login" required>*@
                            @Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })
                            <div class="col-md-10">
                                @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
                            </div>
                        </div>


                        <div class="text-center">
                            <button type="submit" class="btn btn-template-main"><i class="fa fa-user-md"></i> Register</button>
                        </div>
                    </form>
                </div>
            </div>
            <div class="col-md-6 hidden-sm hidden-xs">
                <div class="box" style="padding-left:14px; padding-right:14px;">
                    <h2 class="text-uppercase">Login</h2>

                    <p class="lead">Already our customer?</p>

                    <hr>

                    <form action="@Url.Action("Login","Account")" method="post">
                        <div class="form-group">
                            <label for="text">Username or Email<p style="color:red; display:inline"> *</p></label>
                            <input type="text" class="form-control" id="email" required>
                        </div>
                        <div class="form-group">
                            <label for="password">Password <p style="color:red; display:inline"> *</p></label>
                            <input type="password" class="form-control" id="password" required>
                            <br>
                            <a href="@Url.Action("PasswordReminder","Home")"<label style="text-decoration:underline">Forgot your Password?</label></a>                          
                        </div>
                        <div class="text-center" style="padding-top: 7px;">
                            <button type="submit" class="btn btn-template-main"><i class="fa fa-sign-in"></i> Log in</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <!-- /.row -->
    </div>
    <!-- /.container -->
</div>
<!-- /#content -->

然而,继其他问题之后,这一问题仍然存在。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-06 13:19:11

您必须将令牌放在表单中:

代码语言:javascript
代码运行次数:0
复制
<form action="@Url.Action("Register","Account")" method="post">
    @Html.AntiForgeryToken()

您把它放在form元素打开之前,所以它没有包含在表单POST中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36462459

复制
相关文章
Python批量处理Excel数据后,导入SQL Server
紧接昨天的文章Windows下载安装配置SQL Server、SSMS,使用Python连接读写数据,我们已经安装和配置好了sqlserver,也成功测试了如何利用Python连接、读写数据到数据库。
老表
2022/02/16
4.7K0
Python批量处理Excel数据后,导入SQL Server
将Excel文件数据库导入SQL Server
将Excel文件数据库导入SQL Server的三种方案//方案一: 通过OleDB方式获取Excel文件的数据,然后通过DataSet中转到SQL Server
Java架构师必看
2021/03/22
2.3K0
Excel 日期和时间函数[通俗易懂]
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/168355.html原文链接:https://javaforall.cn
全栈程序员站长
2022/09/20
1.8K0
Excel 日期和时间函数[通俗易懂]
mysql导入excel文件_将Excel数据导入MySQL「建议收藏」
去年的投资统计月报数据量庞大,原始表格是xls格式(还是EXECL2003的),单个sheet最大只能放几万行,但数据总量有10万行以上,于是只能存成两个sheet。EXECL2010格式倒是单个sheet可以放得下,可是居然不能将数据完整的从一个sheet复制粘贴到另一个sheet(可能是因为行数太多)。正好想学习一下execl数据导入MySQL数据库的方法,于是开始尝试。
全栈程序员站长
2022/10/02
16.1K0
mysql导入excel文件_将Excel数据导入MySQL「建议收藏」
给Typecho的Sitemap插件做谷歌站长平台爬虫适配(将文章页lastmod的日期时间改为单日期)
因为没有了解过Typecho插件编写规则,所以没有直接动插件,而是采用一种曲线救国的方法。
kr
2022/06/15
3.1K0
一行代码做Excel导入导出
开发中经常会遇到excel的处理,导入导出解析等等,java中比较流行的用poi,但是每次都要写大段工具类来搞定这事儿,此处推荐一个别人造好的轮子【easypoi】,下面介绍下“轮子”的使用。
小尘哥
2018/08/15
4960
一行代码做Excel导入导出
linux 日期转换时间戳_将时间戳转为时间
最近项目上需要用到时间戳,查找了资源终于找到了实现方式,最后时间戳还需要转换成具体的日期格式,查阅了一些资料,还是没有找到具体的实现方式,所以这里总结一些,防止其他小伙伴就掉坑,实现是在freeRTOS系统上的,当前我在linux下尝试实现以下。
全栈程序员站长
2022/11/10
10.5K0
linux 日期转换时间戳_将时间戳转为时间
python将日期转换为时间戳_python – 将日期时间转换为时间戳,然后再返回
>>> local = datetime(2014, 1, 30, 23, 59, 40, 1999)
用户7886150
2021/01/19
3.5K0
Excel实战技巧:使用日期/时间值
了解如何使用Excel日期值可以帮助我们在日常电子表格工作中节省大量时间,本文就来介绍如何使用它们的技巧。
fanjy
2022/11/16
3.9K0
Excel实战技巧:使用日期/时间值
删除重复值,不只Excel,Python pandas更行
在Excel中,我们可以通过单击功能区“数据”选项卡上的“删除重复项”按钮“轻松”删除表中的重复项。确实很容易!然而,当数据集太大,或者电子表格中有公式时,这项操作有时会变得很慢。因此,我们将探讨如何使用Python从数据表中删除重复项,它超级简单、快速、灵活。
fanjy
2022/04/13
6.1K0
删除重复值,不只Excel,Python pandas更行
Word 技术篇-段落的前后间距单位磅改为行,行改为磅
很多时候,比如我们写论文,word的格式是有严格要求的,我们要一丝不苟的按照要求来。因为,这是一种规范,也是是一种礼仪。
小蓝枣
2020/09/23
1.8K0
JS将日期转换为时间戳
1.getTime() 精确到毫秒 let date = new Date() let timeStamp = date.getTime() console.log(timeStamp) // 1606704849115 2.valueOf() 精确到毫秒 let date = new Date() let timeStamp = date.valueOf() console.log(timeStamp) // 1606704906237 3.parse() 精确到秒,毫秒会用000替代 let date
peng_tianyu
2022/12/15
13.3K0
将数据从 SQL Server 导入 Azure Storage Table
最近有个需求要将数据存储从 SQL Server 数据库切换到 Azure Storage 中的 Table。然而不管是 SSMS 还是 Azure Portal 都没有提供直接的导入功能,是不是又想自己写程序去导数据了?其实不用!没有点过数据库天赋的我996了一个晚上,终于找到了点点鼠标就搞定的方法,今天分享给大家。
Edi Wang
2020/06/15
2K0
Word文档段落的前后间距单位磅改为行,行改为磅方法演示
很多时候,比如我们写论文,word 的格式是有严格要求的,我们要一丝不苟的按照要求来。因为,这是一种规范,也是是一种礼仪。
小蓝枣
2023/05/27
1.8K0
Word文档段落的前后间距单位磅改为行,行改为磅方法演示
Jenkins时间修改为北京时间
jenkins安装后时间一直是utc时间,不太方便。 系统管理->脚本命令行 运行: System.setProperty('org.apache.commons.jelly.tags.fmt.tim
乔达摩@嘿
2020/09/11
2.2K0
Jenkins时间修改为北京时间
如何用一行代码实现excel导入导出
早期我们实现excel导入导出的技术方案,可能会不假思索的选用Apache poi、jxl。但他们存在内存消耗大,编码相对繁琐。好在现在阿里开源了EasyExcel,看它的名字大概就可以猜出来,这框架的一个特点就是容易使用。其次easyExcel省内存。下图是使用easyexcel消耗的内存图
lyb-geek
2020/01/16
2.7K0
如何用一行代码实现excel导入导出
100000行级别数据的Excel导入优化之路
由实施 / 用户 将别的系统的数据填入我们系统中的 Excel 模板,应用将文件内容读取、校对、转换之后产生欠费数据、票据、票据详情并存储到数据库中。
程序员大彬
2023/03/01
1.2K0
100000行级别数据的Excel导入优化之路
将excel文件导入到数据库
参考:http://blog.csdn.net/jayxujia123/article/details/13684313
保持热爱奔赴山海
2019/09/18
4.5K0
将excel文件导入到数据库
使用vb将excel导入PowerDesigner,生成表结构
3、 打开PowerDesigner,创建物理模型(Physical Data Model)
用户5640963
2019/07/25
1.7K0
使用vb将excel导入PowerDesigner,生成表结构
点击加载更多

相似问题

Server :将Excel导入Server时日期格式更改为nvchar

13

将日期-时间数据导入excel

12

Excel使用MSQuery将时间格式更改为日期时间

119

如何将日期时间( Server)转换为Excel日期时间?

34

将字符串日期列更改为日期时间Server

26
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文