[英]Why do i get 404 error when posting from form in azure app service but It works perfectly in localhost
Below is the form code下面是表格代码
@{ ViewData["Title"] = "ModelTrain"; ViewBag.Center = true; } <form method="post" class="text-center" asp-controller="Home" asp-action="Index"> <div class="form-group text-center w-50 mx-auto"> <input type="text" name="url" class="form-control my-2" id="url" placeholder="Добавить ссылку профиля " /> </div> <input type="submit" value="Обучмть модель" class="submit btn btn-secondary" /> </form>
And Below is the Controller code下面是 Controller 代码
public class HomeController : Controller
{
[HttpGet]
public IActionResult Index()
{
return View();
}
[HttpPost]
public async Task<IActionResult> Index(String url)
{
ControlObject control = new ControlObject();
control.body_profile = url;
control.profile = true;
var json = JsonConvert.SerializeObject(control);
var firebaseClient = new FirebaseStorage("hackathontest-e8d57.appspot.com");
var path = @"C:\Users\emiol\source\repos\HackathonFiles\HackathonFiles\TextFile1.txt.txt";
System.IO.File.WriteAllText(path, json);
using (FileStream fs = System.IO.File.Open(path, FileMode.Open))
{
var result = await firebaseClient.Child("TextFileForUrls.txt").PutAsync(fs);
}
return RedirectToAction("Index","Image");
}
}
} ` It returns a 404 error when i try to post back to the form. } ` 当我尝试回发到表单时,它返回 404 错误。 This doesn't happen when testing locally.
在本地测试时不会发生这种情况。 can someone point me to a possible solution please as I've been stuck for a long time on this
有人可以指点我一个可能的解决方案吗,因为我已经被困了很长时间
Try removing div class and have your form code like below:尝试删除 div class 并让您的表单代码如下所示:
@{
ViewData["Title"] = "ModelTrain";
ViewBag.Center = true;
}
<form method="post" asp-controller="Home" asp-action="Index">
<input type="text" name="url" class="form-control my-2" id="url" placeholder="Добавить ссылку профиля " />
<input type="submit" value="Обучмть модель" class="submit btn btn-secondary" />
</form>
Most probably, your form code is incorrectly written and some classes are incorrectly interpreted.最有可能的是,您的表单代码编写不正确,并且某些类的解释不正确。 Try the below basic approach first and then add your custom changes one by one and see where it fails (if the above does not work).
首先尝试以下基本方法,然后逐个添加您的自定义更改,看看它在哪里失败(如果上述方法不起作用)。
Check out this tutorial for reference: https://www.aspsnippets.com/Articles/ASPNet-Core-Form-Submit-Post-Example.aspx查看本教程以供参考: https://www.aspsnippets.com/Articles/ASPNet-Core-Form-Submit-Post-Example.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.