[Solved] jQuery AJAX call asking for user Credentials in ASP.Net

Last Reply 6 months ago By dharmendr

Posted 6 months ago

Hello Together,

i am building a web application with ASP.net and want to get some data from Server side to client side with Ajax request.

My problem is that the Ajax request is asking me for user credentials, but the user is automatically logt on by windows authentication since its a intranet website.

So why he is asking me for authorization? 

Javascript-Code:

        $(function () {
            $.ajax({
                type: "POST",
                url: "Default.aspx/FillerInformations",
                data: '{}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
        });

 Server Side VB.Net Code

Imports System.Data.SqlClient
Imports System.IO
Imports Newtonsoft.Json
Imports System.Web.Services

Public Class _Default
    Inherits Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

    End Sub


    <WebMethod()>
    Public Shared Function FillerInformations() As List(Of Filler)
        Dim constr As String = ConfigurationManager.ConnectionStrings("MESData").ConnectionString
        Using con As New SqlConnection(constr)
            Using cmd As New SqlCommand("EXEC SCZ_TPM_RYC_1_to_xx_Drivers_Main_Dashboard @DateIni = '12/10/2018 6:00:00', @DateFin = '12/11/2018 6:00:00'")
                cmd.Connection = con
                Dim Fillers As New List(Of Filler)()
                con.Open()
                Using sdr As SqlDataReader = cmd.ExecuteReader()
                    While sdr.Read()
                        Fillers.Add(New Filler() With {
                         .PerfR1 = sdr("Performance R1").ToString(),
                         .PerfR2 = sdr("Performance R2").ToString(),
                         .PerfR3 = sdr("Performance R3").ToString(),
                         .PerfR4 = sdr("Performance R4").ToString(),
                         .PerfR5 = sdr("Performance R5").ToString(),
                         .PerfR6 = sdr("Performance R6").ToString(),
                         .PerfR7 = sdr("Performance R7").ToString(),
                         .PerfR8 = sdr("Performance R8").ToString(),
                         .UnplR1 = sdr("unplannedR1").ToString(),
                         .UnplR2 = sdr("unplannedR2").ToString(),
                         .UnplR3 = sdr("unplannedR3").ToString(),
                         .UnplR4 = sdr("unplannedR4").ToString(),
                         .UnplR5 = sdr("unplannedR5").ToString(),
                         .UnplR6 = sdr("unplannedR6").ToString(),
                         .UnplR7 = sdr("unplannedR7").ToString(),
                         .UnplR8 = sdr("unplannedR8").ToString()
                        })
                    End While
                End Using
                con.Close()
                Return Fillers
            End Using
        End Using
    End Function

    Public Class Filler
        Public Property PerfR1() As String
        Public Property PerfR2() As String
        Public Property PerfR3() As String
        Public Property PerfR4() As String
        Public Property PerfR5() As String
        Public Property PerfR6() As String
        Public Property PerfR7() As String
        Public Property PerfR8() As String
        Public Property UnplR1() As String
        Public Property UnplR2() As String
        Public Property UnplR3() As String
        Public Property UnplR4() As String
        Public Property UnplR5() As String
        Public Property UnplR6() As String
        Public Property UnplR7() As String
        Public Property UnplR8() As String
    End Class

End Class

Thanks for help

You are viewing reply posted by: dharmendr 6 months ago.
Posted 6 months ago Modified on 6 months ago

Hi HaxxBoxx,

In your App_Code folder, with in your RouteConfig.cs comment out the following line or change its RedirectMode to Off.

C#

public static void RegisterRoutes(RouteCollection routes)
{
    var settings = new FriendlyUrlSettings();
    //settings.AutoRedirectMode = RedirectMode.Permanent;
    settings.AutoRedirectMode = RedirectMode.Off;
    routes.EnableFriendlyUrls(settings);
}

VB.Net

Public Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    Dim settings = New FriendlyUrlSettings()
    'settings.AutoRedirectMode = RedirectMode.Permanent
    settings.AutoRedirectMode = RedirectMode.Off
    routes.EnableFriendlyUrls(settings)
End Sub