Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

293
Vistas
401 Unautherized error - [Post <url> 401 (Unauthorized)]

I have created a simple Single page .Net application using MVC. So I have now a ready-made project. I don't want it so I made some changes to it.

In startup.cs file I commented the ConfigureAuth(app)

namespace WebApplication1
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {

            //ConfigureAuth(app);
        }
    }
}

Then Under the project folder, I have created the Index.html file and Index.js file

Index.html

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <script type="text/javascript" src="Library/knockout-3.5.0.js"></script>
</head>
<body>
    
    <input type="button" class="button primary small-button50" id="btnUpload" value="Upload" data-bind="click:UploadImageClick" />
    <script type="text/javascript" src="Index.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</body>
</html>

Index.js

function AppviewModel() {
    var self = this;
    

    self.UploadImageClick = function () {
        //alert("Hello");
        $.ajax({
            type: "POST",
            url: "./Home/Test",
            crossDomain: true,
            //data: ko.toJSON(),
            dataType: "json",
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                
                console.log("Success")
            },
            error: function () {
                console.log("Failed to refresh the images");
            }
        });
    };
}
ko.applyBindings(new AppviewModel());

In HomeController I have written the code for Test method

HomeController.cs

public class HomeController : Controller
    {

        [HttpPost]
        public int Test()
        {
            return 1;
        }
    }

All this I did just because I want to make an application without razor pages. So after running this application I am getting URL something like http://localhost:54720/ then I am putting Index.html in front of it then it is showing me Index page http://localhost:54720/Index.html and Javascript file is also running properly but my Ajax call is not working it is throwing an error of the 401 (Unauthorized).

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda