Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6748205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:32:15+00:00 2026-05-26T12:32:15+00:00

I get a 401 Unauthorized when my ajax is doing a POST event this

  • 0

I get a 401 Unauthorized when my ajax is doing a POST event this is only when the project is being run through sitecore. This all works like a charm I need a work around for sitecore this is my current setup.

I followed Link 1 to setup my code, so I have the following:

MasterLayout.aspx:

<script src="jsfile.js" type="text/javascript"></script>

<script src="../../../content/javascript/jquery-1.6.2.min.js"></script>

MasterLayout.aspx.cs:

using System.Web.Services;

[WebMethod]
public static string GetDate()
{
   return DateTime.Now.ToString();
}

MyCharts.ascx

<div class="Result" id="Result">Click here for the time.</div>

jsfile.js:

$(document).ready(function() {
// Add the page method call as an onclick handler for the div.

    $('.Result').click(function() {
        $.ajax({
            type: "POST",
            url: "MyCharts.aspx/GetDate", // MyCharts.aspx is a logical page created in sitecore physically it loads MasterLayout with MyCharts within that.
            data: "{}",
            contentType: "application/json",
            dataType: "json",
            success: function(msg) {
                // Replace the div's content with the page method's return.
                $(".Result").text(msg.d);
            }
        });
    });
});

When debugging javascript tries to POST HelloWorld and I get:

"Message":"Authenticationfailed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"

Link 1: http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

Related Question: Getting "401 Unauthorized" error consistently with jquery call to webmethod

My Related Question: https://stackoverflow.com/questions/7837532/get-my-html-and-javascript-to-perform-postback-ajax-call

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:32:16+00:00Added an answer on May 26, 2026 at 12:32 pm

    I wanted a solution that enabled me to allow the page I was doing the post on to be run through sitecores context. If you don’t mind the page ignoring the context look at Mark Ursino answer it will work like a charm.

    My answer does the following:

    Javascript:

    function MySuperCoolFunction() {
        strUser1 = document.getElementById("Symbol1").innerHTML;
        strUser2 = document.getElementById("Symbol2").innerHTML;
    
        var join = strUser1 + "," + strUser2;
    
        __doPostBack('upCurrencyCharts', join);
    }
    

    .ascx/.aspx:

    <asp:UpdatePanel runat="server" ID="upCurrencyCharts" OnLoad="upCurrencyCharts_onload">
        <ContentTemplate>
    
               // My Content Here  
    
         </ContentTemplate> 
     </asp:UpdatePanel> 
    

    .cs:

    protected void upCurrencyCharts_onload(object sender, EventArgs e)
    {
        string item1 = null;
        string item2 = null;
    
        if (IsPostBack)
        {      
           string items = Request["__EVENTARGUMENT"];
           string[] partsArray = items.Split(',');
    
                for (int i = 0; i < partsArray.Length; i++)
                {
                    if (i == 0)
                    {
                        item1 = partsArray[i];
                    }
    
                    if (i == 1)
                    {
                        item2 = partsArray[i];
                    }
                }
            }
    
            // do something with item1 and 2 here.. in mycase feed to database.
    

    The javascript forces a postback event on my update panel, and parses a string of parameters I am sending through to the backend of my website. Onload event triggers on postback and fires anything I do in my onload event in this case puts the items into an array to split them and then puts them into a database. Simples. Thanks everyone for there help in this. 😀

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing user auth via an Ajax post-request in Rails, and I thought that
When try to POST a status update to LinkedIn, I got 401 Unauthorized error.
No matter how I configure the Credentials property I get a 401 exception when
I get the following error when running my Visual Studio 2008 ASP.NET project (start
I get this error: Can't locate Foo.pm in @INC Is there an easier way
I get the following error when trying to run the latest Cygwin version of
I'm trying to do an ajax (restful service) call using $.get. It works perfectly
Getting sick with asp.net permission madness... This time, I Just cant AJAX-CALL any kind
Hey all, I am using the Pinboard API for adding a post from my
I am getting a 401 unauthorized error when I try to read an XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.