简体   繁体   中英

Calling .net web service behind webform authentication page from javascript

I am trying to call a web service that is located on a web server that requires web form authentication

 $.ajax({
                    type: "Get",
                    url: "http://SomeIPAddressThatIDontWantToShare/WebServices/GetServerData.asmx/GetOPCHist_Last4h",
                    data: { OPCName: OPCName_Passed, OPCTable: OPCTable_Passed },
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $.each(data, function (index, element) {
                            T1.push([new Date(element.DateAndTime).getTime(), element.T1]);
                        });
                    },
                    error: function (request, status, error) {
                        alert(request.status + ' ' + request.responseText);
                    }
                })

However when doing so it always hits the error state with a state of "0" and nothing for the responseText. I manually authenticated on the browser before hitting the page.

So the question is, do I have to do web form authentication from javascript, and if so how?

Also is this error even related to web form authentication or is status of 0 possibly something totally different.

I verified I can access that webservice once I log in from a browser.

If your service is under webforms protection, you have to, of course, login first. Check this to try to remove webforms protection for your ws. Or you can try this one to work within webforms.

I hope this can help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM