c# - 为什么我在 azure 应用程序服务中从表单发布时收到 404 错误,但它在 localhost 中运行良好

标签 c# asp.net .net azure

下面是表单代码

@{
    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>

下面是 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");
    }
}

} ` 当我尝试回发到表单时,它返回 404 错误。在本地测试时不会发生这种情况。有人可以给我指出一个可能的解决方案吗,因为我已经被困在这个问题上很长时间了

最佳答案

尝试删除 div 类并使用如下所示的表单代码:

@{
    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>

最有可能的是,您的表单代码编写不正确,并且某些类的解释不正确。首先尝试以下基本方法,然后一一添加您的自定义更改,看看哪里失败(如果上述方法不起作用)。

查看本教程以供引用:https://www.aspsnippets.com/Articles/ASPNet-Core-Form-Submit-Post-Example.aspx

关于c# - 为什么我在 azure 应用程序服务中从表单发布时收到 404 错误,但它在 localhost 中运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65055852/

相关文章:

c# - 如何用C#从php到asp.Net调用json_encode函数?

c# - 即使使用值 Entity Framework ,实体属性也为空

c# - 如何为自定义队列实现 <IEnumerable>?

asp.net - ReportViewer 2010 未从代码加载数据源

asp.net - ASP.NET MVC 中是否有嵌套母版页?

c# - 为什么在 C# 应用程序中将 IL 代码打包到 exe 中?

.net - 扩展方法是否太昂贵?

c# - WPF ClickOnce DPI 感知 Per-Monitor v2

ASP.NET:如何在 aspx 中右对齐图像?

asp.net - 使用带有代码隐藏的网络表单通过反射引发事件