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
Webmethod Should be shared (vb) / static (C#) if you are getting ERROR 500, mark your method as Shared/Static and you are done.
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
Populating a Razor Dropdownlist from a List<Object> in MVC
How to Restart My C# Winform Application
Adding Placeholder Text to Textbox
Dynamically Add C# Properties at Runtime
.Net Out of Memory Exception - Used 1.3Gb But Have 16Gb Installed
C# Listview, How to Add Items to Columns 2, 3 and 4 etc
Convert an Image (Selected by Path) to Base64 String
Random String Generator Returning Same String
Calculating Distance Between Two Latitude and Longitude Geocoordinates
Xmlserializer Giving Filenotfoundexception at Constructor
How to Get the Title of the Current Active Window Using C#
Is There Any Async Equivalent of Process.Start
Binding List<T> to Datagridview in Winform
Validate Image from File in C#
Check for Column Name in a SQLdatareader Object
Generating Permutations of a Set (Most Efficiently)
Tolist()-- Does It Create a New List
How to Ignore Unknown Enum Values During JSON Deserialization