ASP.NET Calling Webmethod with Jquery Ajax "401 (Unauthorized)"

ASP.NET Calling WebMethod with jQuery AJAX 401 (Unauthorized)


Problem solved

This was driving me crazy.

Inside ~/App_Start/RouteConfig.cs change:

settings.AutoRedirectMode = RedirectMode.Permanent;

To:

settings.AutoRedirectMode = RedirectMode.Off;

(Or just comment the line)

Also if friendly URLs are enabled you need to change

url: "ConsultaPedidos.aspx/GetClients",

To:

url: '<%= ResolveUrl("ConsultaPedidos.aspx/GetClients") %>',

Hope this help somebody else

ASP.Net 3.5 WebMethod called using jQuery AJAX throws Unauthroized 401 error

For doing that, you can adding below code in web.config:

<authorization>
<allow users="*" />
</authorization>

For more information, please see allow Element for authorization.

401:unauthorized when I try to call a method via AJAX in .net

Found the answer here: ASP.NET Calling WebMethod with jQuery AJAX "401 (Unauthorized)"

I have used
settings.AutoRedirectMode = RedirectMode.Off; instead of RedirectMode.Permanent in ~/App_Start/RouteConfig.cs, which fixed the issue.

Getting 401 Unauthorized error consistently with jquery call to webmethod

Yes, it did get working! Since Sitecore CMS does perform URL rewriting to generate friendly URLs (it assembles the pages in layers, dynamically, similar to Master Page concept), it occurred to me that it may be causing some problem the initially caused the 401 error. I verified this by creating a separate project with a single ASPX--and with some work I was able call the web methods and get values using the jquery. I then created nearly identical ASPX in my web root, but told Sitecore to ignore it when a request is made to it (IgnoreUrlPrefixes in the web.config), after some work I was able also get it to work successfully! Thanks for your help.

ASP.NET Webmethod always Returns 401


  1. Webmethod Should be shared (vb) / static (C#) if you are getting ERROR 500, mark your method as Shared/Static and you are done.

  2. About Error 401: If you are using forms authentication remember to allow anonymous access to your login page by doing this on your web.config:

    <location path="Login.aspx">
    <system.web>
    <authorization>
    <allow users="*"/>
    </authorization>
    </system.web>
    </location>

.net and jquery all of a sudden giving me 401 err

The issue i could understand is when a user tries to login say i just sent a request for login.. at this time i am not logged in means i dont have any role currently and you have put an authorize filter to ajax controller with allowing some roles

now to remove this issue put allowannonymus attribute only to your Login action inside ajax controller

like

  [AllowAnonymous]
public async Task<ActionResult> Login()
{
}

p.s :- and dont forget to put it in post action and to the register action if you have one



Related Topics



Leave a reply



Submit