无法找到用于回调HttpPost方法的资源

时间:2018-03-24 23:09:13

标签: asp.net-mvc

我有一个MVC项目。我的网站连接到银行网关,成功付款后,结果POST到我的网站运行VerifyPayment方法(此方法的类型为HttpPost)。

 [HttpPost]
   // [AllowAnonymous]
    public ActionResult VerifyPayment( VerifyResult Vresult )
    {
        try
        {
            // var transact = Request.Form["transId"];
            // TempData["msg"] = $"<script>alert('transaction id is: {transact}');</script>";
            //// for test
            // return View(new VerifyResult() { success = true, SuccessMessage = "nice", Amount = "20000" });
            if ( !string.IsNullOrEmpty(Request.Form["transId"]) )
            {
                Payment ob = new Payment();
                string result = ob.verify(Request.Form["transId"].ToString());
                JsonParameters Parmeters = JsonConvert.DeserializeObject<JsonParameters>(result);

                if ( Parmeters.status == 1 )
                {
                    var userId = User.Identity.GetUserId();
                    var user = db.Users.Where(u => u.Id == userId).FirstOrDefault();
                    user.SuccessfullPayment = true;
                    user.FactorNo = User.Identity.GetUserId();
                    user.TraceNo = Request.Form["traceNumber"];
                    user.TransId = int.Parse(Request.Form["transId"]);
                    user.CardNo = Request.Form["cardNumber"];
                    user.PurchasedDate = DateTime.Now;
                    user.State = Parmeters.status;
                    user.Message = Request.Form["message"];
                    db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                    Vresult.success = true;
                    Vresult.TransActionID += Request.Form["transId"].ToString();
                    Vresult.Amount += Parmeters.amount.ToString();
                    Vresult.SuccessMessage = "پرداخت با موفقیت انجام شد.";
                    return RedirectToAction("Index", "DownloadEbook");
                }
                else
                {

                    Vresult.error = true;
                    Vresult.ErrorMessage = "کدخطا : " + Parmeters.errorCode + "<br />" + "پیغام خطا : " + Parmeters.errorMessage;

                }
            }
        }
        catch ( Exception )
        {
            Vresult.error = true;
            Vresult.ErrorMessage = "متاسفانه پرداخت ناموفق بوده است.";
        }

        return View(new AllNeededModels() { VerifyResult = Vresult });
    }

VerifyPayment方法有自己的View.cshtml文件,名为“VerifyPayment.cshtml”。

@model Mahdavimanesh.Models.AllNeededModels
@{
   ViewBag.Title = " ";
   }

       <div class="container">
          @if (Model.VerifyResult.success)
              {
     <div class="row" style="margin-top: 50px;">
        <div class="col-lg-6 center-block" style="float: none;">
            <div class="alert alert-success">
                <asp:Label ID="lblSuccess" runat="server" ForeColor="Green" 
          Text=""></asp:Label>
                @Model.VerifyResult.SuccessMessage
                <br />
                  : @Model.VerifyResult.TransActionID
                <br />
                 : @(Model.VerifyResult.Amount)
            </div>
        </div>
    </div>
             }

         else

           {


             <div class="row" style="margin-top: 50px;">
                  <div class="col-lg-6 center-block" style="float: none;">
                     <div class="alert alert-danger">
                  @Model.VerifyResult.ErrorMessage
                </div>
              </div>
             </div>


            }

        </div>

我的localhost上的一切正常。但是,当我发布网站,成功付款并回电到我的网站后,它通知我“资源无法找到”的错误。我认为问题是由于HttpPost VerifyMethod引起的,而VerifyPayment.cshtml是针对HttpGet方法的。如果这样,为什么它在我的本地机器上工作?

有任何线索吗?

0 个答案:

没有答案