none
401 Error on IIS 6.0 while accessing other website url RRS feed

  • Question

  • Hi Everyone,
     
    We are getting 401 (unauthorised access) error while trying to access edms or SharePoint link from code behind, following is the block of code that is used to access the edms or SharePoint link.
     
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(txtLink.Text);
    request.UseDefaultCredentials = true;

    request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
    request.ImpersonationLevel = TokenImpersonationLevel.Delegation;
    CookieContainer cookiescont = new CookieContainer();
    request.CookieContainer = cookiescont;
    request.AllowWriteStreamBuffering = false;
    request.PreAuthenticate = true;
    request.AllowAutoRedirect = true;
    WebResponse wsc = request.GetResponse();
     
    Note: Following are the environmental and other details.
    • The website is hosted on IIS 6.0 AND Windows 2003.
    • Following is the setting in web.config
           <authentication mode ="Windows">
           </authentication>   
           <authorization>
               <deny users="?"/>
           </authorization>
    • Surprisingly: Same block of code is working on my local machine which have XP and IIS 5.1
    Any help will be appreciated.
    Best Regards,
    Anuj Kumar 
    0091 9313499294

    Anuj
    Thursday, May 20, 2010 7:07 AM

Answers

  • Hi,

    You are denying access to anonymous users using <deny users="?"/> in web.config. Allow the specific users to access application using <allow users="user1,user2" />

    When you run the asp.net application in IIS 5.x in Windows XP, It runs under the ASPNET account. If you are using Windows authentication and you are a local administrator in the PC, the code might be running under the security context of your account and hence you are able to run the above code in your post.

    But you may not be an administrator in Windows 2003 and access to the site is not provided to your account using <allow> element in web.config. So you may not be able to access the site using the above code.

    Thursday, May 20, 2010 7:50 AM