简体   繁体   中英

Routing error 404 only when deployed in UAT web server. Works locally. ASP.NET Core

解决方案资源管理器

I've completed testing my ASP.NET Core app locally, and it works fine. However I'm getting 404 errors for a trigger on my view after publishing to our UAT server and I cannot determine why. I'm possibly missing something obvious and would appreciate fresh eyes. Thank you.

I have tried amending the routing in StartUp and attempted mixed routing in my controller.

Relevant part of Configure method in startup.cs:

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=StartPage}/{id?}");
        });

Relevant form in my StartPage view:

    <form action="@Url.Action("StartSlsProcess", "Home")"  method="post" enctype="multipart/form-data" id="trigger">
        <div id="process-trigger">
            @(Html.DevExtreme().Button()
                  .Text("Start SLS")
                  .Type(ButtonType.Success)
                  .UseSubmitBehavior(true)
                  )

        </div>
    </form>

Method in HomeController:

    [HttpPost]
    public ActionResult StartSlsProcess()
    {

        var empty = new string[0];

        ConsoleApp.Program.StartProcessFromUI(empty);

        return new EmptyResult();

    }

I would expect when the button is pushed on the view that it triggers the StartProcessFromUI method on my console app, continues the separate process and refreshes the view, as it does locally.

Edit: what is further confusing the issue is that my other Action works fine, and is set up the same:

        <form action="@Url.Action("Upload", "Home")" method="post" enctype="multipart/form-data" id="uploader">
        <div id="fileuploader-container">
            @(Html.DevExtreme().FileUploader().Name("file")
                  .ID("file-uploader")
                  .Accept("*")
                  .UploadMode(FileUploadMode.Instantly)
                  .UploadUrl(Url.Action("Upload", "Home"))
                  //.OnUploadError("fileUploader_onUploadError")

                  //.OnValueChanged("fileUploader_valueChanged")
                  )  
        </div>
    </form>

HomeController method:

[HttpPost]
    public ActionResult Upload()
    {
        try
        {
            var file = Request.Form.Files["file"];
            var path = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");

            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            using(var fileStream = System.IO.File.Create(Path.Combine(path, file.FileName))) {
                file.CopyTo(fileStream);
                fileStream.Flush();
            }

            MoveFileFromServer(path, file); 

        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            throw;
        }

        return new EmptyResult();

    }

Additionally, the method on my ConsoleApp, StartProcessFromUI actually gets hit, it's just that the 404 Error is then returned in the foreground.

At least for the C# side, I can tell you it is not a programming issue. As a general rule the networking code does not care if the other end is on the same computer, the same switch, or the Voyager 2 Probe.

Making certain there is a path there is a Networking Problem, not a programming one. As your Title says, the error is a 404/Routing one. So it is definitely somewhere in the Networking. Maybe the Server is not set up to allow external (non-Localhost) Connections, or some similar security feature. Many default profiles are created with such settings for security reasons. It could also be a overagressive Firewall.

When in doubt, you can just verify it with a simple HTML file, that should be delivered as stored on the disk.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM