The remote server returned an error 401 unauthorized
Actually, A Customer has requested to be able to get SharePoint Calendar entries "Meetings and events" as an XML File, and there is a dll file that is used for dealing with lists' data as XML, So I have built an .aspx page that only creates a System.Net.HttpWebRequest in
order to get the above mentioned XML. However the problem was that when I enter the url that directly deal with the owssvr.dll file, then the requests returns the expected XML file:
http://MySharepointServerURL/_vti_bin/owssvr.dll?Cmd=Display&List=161D7884-FD59-4464-AF00-40F653A214F8&XMLDATA=TRUE
Nevertheless, When requesting my custom .aspx page that should do the same, then unauthorized error appears to me:
http://MySharepoint ServerURL/_vti_bin/getListItemsXML.aspx
The inline code of my aspx page:
<%@ Page Language="C#" contentType="BinaryStream" %> <script
language="c#"
runat="server"> protected void Page_Load(object sender, EventArgs e) { string strURL = Microsoft.SharePoint.SPContext.Current.Web.Url + "/_vti_bin/owssvr.dll?Cmd=Display&List=161D7884-FD59-4464-AF00-40F653A214F8&XMLDATA=TRUE"; System.Net.HttpWebRequest objWebRequest = null; System.Net.HttpWebResponse objWebResponse = null; System.IO.StreamReader streamReader = null; string strHTML = null; System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object s, System.Security.Cryptography.X509Certificates.X509Certificate
certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { return true; }; objWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strURL); objWebRequest.Method = "GET"; objWebRequest.Credentials = System.Net.CredentialCache.DefaultCredentials; objWebResponse = (System.Net.HttpWebResponse)objWebRequest.GetResponse(); streamReader = new System.IO.StreamReader(objWebResponse.GetResponseStream()); strHTML = streamReader.ReadToEnd(); streamReader.Close(); objWebResponse.Close(); objWebRequest.Abort(); Response.ContentType = "text/xml"; Respnbsp; strHTML = streamReader.ReadToEnd(); streamReader.Close(); objWebResponse.Close(); objWebRequest.Abort(); Response.End(); } </script>Actions Required Resolve the "error 401 unauthorized"
YOU COULD REFER TO KB896861 (HTTP://SUPPORT.MICROSOFT.COM/KB/896861)
TO WORKAROUND THE ISSUE.
I QUOTED THE METHOD 2 IN THE KB FOR YOUR INFORMATION:
TO DISABLE THE LOOPBACK CHECK. FOLLOW THESE STEPS:
- CLICK START, CLICK RUN, TYPE REGEDIT, AND THEN CLICK OK.
- IN REGISTRY EDITOR, LOCATE AND THEN CLICK THE FOLLOWING REGISTRY KEY: HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\CONTROL\LSA
- RIGHT-CLICK LSA, POINT TO NEW, AND THEN CLICK DWORD VALUE.
- TYPE DISABLELOOPBACKCHECK, AND THEN PRESS ENTER.
- RIGHT-CLICK DISABLELOOPBACKCHECK, AND THEN CLICK MODIFY.
- IN THE VALUE DATA BOX, TYPE 1, AND THEN CLICK OK.
- QUIT REGISTRY EDITOR, AND THEN RESTART YOUR SERVER.
References
The following reference is related to my issue.