I use web methods in a couple of places in the intranet site im working on and they work fine, however one page is constantly throwing a HTTP 401 error every time I try access the web method.
Im not sure how to aproach this issue, I have tried commenting everything out of the web method, and still get the 401 error, even a basic connect to the database just doing SELECT 1
does not show up when I watch the DB with profiler.
My web.config is the same for all pages in the intranet and I cannot see any differences in my ASP.Net page compared to pages where web methods work.
Can anyone tell me why this could be happening for just this page and not others? And also how can I get around this problem?
The ASP.Net Code (called from the OnClientClick of a button)
function SendEmails()
{
var Grid = document.getElementById("instructorGrid");
var mailBody = document.getElementById("txtMailBody");
var ddlDutyPeriod = document.getElementById("DDL_DutyPeriods");
var cell = Grid.rows[i].cells;
var HTML = cell[0].innerHTML;
var chkBox = cell[5].innerHTML;
PageMethods.TestMethod()
}
The script manager
<asp:ScriptManager ID="ScriptManager1"
runat="server"
EnableScriptGlobalization="true"
EnablePageMethods="true"
EnableScriptLocalization="true">
</asp:ScriptManager>
The VB.Net Code
<System.Web.Services.WebMethod()>
Public Shared Sub TestMethod()
'Dim conn1 As New SqlConnection(ConfigurationManager.ConnectionStrings("Blueprint").ToString())
'Dim cmd2 As New SqlCommand
'cmd2.CommandType = CommandType.Text
'cmd2.CommandText = "SELECT 1"
'cmd2.Connection = conn1
'conn1.Open()
'cmd2.ExecuteNonQuery()
'conn1.Close()
End Sub
The Fiddler results
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Authorized</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Not Authorized</h2>
<hr><p>HTTP Error 401. The requested resource requires user authentication.</p>
</BODY></HTML>
UPDATE:
I have tried using impersonating the user in code like half way down in this link http://support.microsoft.com/kb/306158 however I cant do that since the method is a webmethod.
I have also tried adding anonymous access to my login page in web.config as suggested below but this also hasnt helped
I think you are using FormsAuthentication. You must give your login page anonymous access.
<location path="Login.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
Add the impersonation tag in your web.config file. This should allow impersonation with a specific account when trying to access your web method. See this support article for direction.
<system.web>
<identity impersonate="true" userName="Yang" password="bar" />
</system.web>
It's a long shot but do you have this in your Web.Config?
<system.web.extensions>
<scripting>
<webServices>
<authenticationService enabled="true" />
</webServices>
</scripting>
</system.web.extensions>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With