The following code works just fine without FriendlyUrls turned on for an ASP.Net Web Forms project:
After spending way too much time on this, I found out that I needed to change this in App_Start/RouteConfig.cs:
//settings.AutoRedirectMode = RedirectMode.Permanent;
settings.AutoRedirectMode = RedirectMode.Off;
public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
var settings = new FriendlyUrlSettings();
//Esta wea se deshabilita para que funcione ajax autocomplete.
//settings.AutoRedirectMode = RedirectMode.Permanent;
settings.AutoRedirectMode = RedirectMode.Off;
routes.EnableFriendlyUrls(settings);
}
}
So, ultimately I got the solution to my question by making following changes to my project:
Add FriednlyUrls to the project.
Remove the line in RegisterRoutes method that sets settings.AutoRedirectMode
property in App_Start/RouteConfig.cs
(note that setting it to RedirectMode.Permanent or RedirectMode.Off did NOT work for me)
Add authorization in web.config as follows under system.web section
<authorization>
<allow users="*" />
</authorization>
Modify the url in ajax call set up to use Microsoft.AspNet.FriendlyUrls.Resolve function in order to get the correct url as below:
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
url: '<%=Microsoft.AspNet.FriendlyUrls.FriendlyUrl.Resolve("/Default.aspx/GetData")%>',
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (result) {
var resultData = (result.d? result.d : result);
alert(resultData);
},
error : function(){
alert('error');
}
});
});
</script>