Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

300
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!