简体   繁体   English

为什么从 azure 应用程序服务中的表单发布时出现 404 错误,但它在 localhost 中完美运行

[英]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.

相关问题 为什么我会从Azure收到错误消息“不支持ITraceWriter服务类型。” - Why do I get the error “The service type ITraceWriter is not supported.” from Azure? 为什么我在确保 Azure blob 先存在时会得到 404? - Why do I get a 404 on an Azure blob when I ensure it exists first? Google登录适用于localhost和测试服务器,但不适用于azure网站(应用服务) - Google login works on localhost and test server, but not azure website (app service) “/”应用程序中的服务器错误。 无法找到该资源。 (404) 将 WCF 服务部署到 Azure 应用服务时 - Server Error in '/' Application. The resource cannot be found. (404) when deploying WCF service to Azure App Service 为什么在尝试将调试过程附加到Microsoft Azure应用程序服务时出现错误? - Why I get error while trying to attached debugging process to a Microsoft Azure app service? 为什么我在尝试连接到“localhost”时会收到“拒绝访问”错误? - Why do I get an 'Access Denied' error when trying to connect to 'localhost'? 从Web应用程序调用Web服务时拒绝连接时,可以从本地主机正常工作 - Getting connection refused when calling a web service from a web app works fine from localhost 为什么我在使用 async/Task 时在 Azure Function 中出错,但在 Console App 中使用它们时却没有错误? - Why I get error in Azure Function when use async/Task, but when use these in Console App, there is no error? Azure Blob 存储从 Azure 应用服务返回 404 - Azure Blob Storage Returns 404 from Azure App Service 如何从应用程序以管理员身份访问Azure移动服务? - How do I access an Azure Mobile Service as an admin from an app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM