Trang web của tôi đang tăng ngoại lệ khoảng 20 lần mỗi ngày, thường biểu mẫu hoạt động tốt nhưng có trường hợp xảy ra sự cố này và tôi không biết tại sao lại ngẫu nhiên như vậy .Cookie chống giả mạo "__RequestVerificationToken" không có mặt
này được đăng nhập ngoại lệ bởi ELMAH
500 HttpAntiForgery Các yêu cầu chống giả mạo Cookie __RequestVerificationToken" là không có mặt.
Nhưng hình thức nó được gửi token như hiển thị trên XML log by elmah
<form>
<item name="__RequestVerificationToken">
<value string="DNbDMrzHmy37GPS6IFH-EmcIh4fJ2laezIrIEev5f4vOhsY9T7SkH9-1b7GPjm92CTFtb4dGqSe2SSYrlWSNEQG1MUlNyiLP1wtYli8bIh41"/>
</item>
<item name="toPhone">
<value string="XXXXXX"/>
</item>
<item name="smsMessage">
<value string="xxxxxxxx"/>
</item>
</form>
Đây là phương pháp của tôi trên bộ điều khiển sử dụng dữ liệu Thuộc tính để kiểm tra xem mã thông báo có vali hay không d hoặc cũng không
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<JsonResult> Send(SMSModel model)
{
// my code goes here
}
Đây là hình thức của tôi về quan điểm
@using (Html.BeginForm("Send", "SMS", FormMethod.Post, new { @class = "form-sms", autocomplete = "off" }))
{
@Html.AntiForgeryToken()
<div class="row">
<div class="col-md-12">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">+53</div>
@Html.TextBoxFor(m => m.toPhone, new { @class = "form-control", placeholder = "teléfono", required = "required", type = "tel", maxlength = 8 })
</div>
</div>
</div>
</div>
<div class="form-group" style="position:relative">
<label class="sr-only" for="exampleInputEmail3">Message (up to 135 characters)</label>
@Html.TextAreaFor(m => m.smsMessage, new { rows = 4, @class = "form-control", placeholder = "escriba aquí su mensaje", required = "required", maxlength = "135" })
<span class="char-count">135</span>
</div>
if (ViewBag.Sent == true)
{
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>Su mensaje ha sido enviado <span class="hidden-xs">satisfactoriamente</span></strong>
</div>
}
if (ViewBag.Error == true)
{
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>Error:</strong> Por favor revise el número de teléfono.
</div>
}
<div class="errorToMany"></div>
<button type="submit" class="btn btn-default btn-block">Enviar SMS</button>
}
Và cách này tôi gửi dữ liệu của tôi sử dụng AJAX
$('form.form-sms').submit(function (event) {
$.ajax({
url: $(this).attr("action"),
type: "POST",
data: $(this).serializeArray(),
beforeSend: function (xhr) {
$('.btn-default').attr("disabled", true);
$('.btn-default').html("Enviando...")
},
success: function (data, textStatus, jqXHR) {
if (data[0] == false && data[1] == "1") {
some code
} else {
location.reload();
}
},
error: function (jqXHR, textStatus, errorThrown) { }
});
return false;
});
Các hình thức hoạt động tốt thời gian nhất nhưng lỗi này giữ xảy ra và tôi không biết tại sao, tôi đã kiểm tra các câu hỏi khác ở đây trên Stack Overflow nhưng không có gì làm việc cho tôi.
Để được giải thích thêm về cách tôi đăng dữ liệu.
Biểu mẫu này để gửi SMS có các trường ToNumber và Message. Khi người dùng nhấp vào nút gửi, chức năng AJAX kiểm soát và đăng nó tuần tự hóa dữ liệu trường của biểu mẫu, khi chức năng của tôi trong bộ điều khiển kết thúc và trả về kết quả JSON cho thấy mọi thứ diễn ra tốt đẹp, phương pháp AJAX sẽ tải lại trang hiển thị người dùng thành công thông điệp.
Bất kỳ ý tưởng nào có thể gây ra sự cố này.
Man, cảm ơn bạn đã giải thích chi tiết, tôi không biết mẹo location.reload (true). Tôi chỉ cần thay đổi mã của tôi và sẽ chờ đến ngày mai để xem nếu không nhận được vấn đề này nữa và sẽ đánh dấu câu trả lời của bạn là chấp nhận nếu đó là trường hợp. –