none
401 error in http ... RRS feed

  • Question

  • hii,
    hey..z der anyone.... who can suggest me some solution to remove 401 error from my application...i've already used authentication manager....
    plzzz...help me..man
    Monday, February 2, 2009 11:47 AM

All replies

  • Hi,

    401 errors can be a bit of a pain to diagnose in WCF.

    There's a good link here to get you started:
    http://blogs.msdn.com/david.wang/archive/2005/07/14/HOWTO_Diagnose_IIS_401_Access_Denied.aspx

    Also, can you provide a bit more detail on your scenario:

    WCF host (IIS version)
    Which binding you are using
    How you have set up security
    What client credentials you are supplying

    Regards,

    Alan


    BloggersGuides.net
    Monday, February 2, 2009 12:15 PM
  • well sir ,
    m using IIS-7.0
    n downloading the data in binary format..n then convert it into the stream..
    using network credential class to send the credential wid request...here m pasting the code snippet ..plzz check it n temme whr m wrong..



    //this is the class which is implement the customize authentication. and the autherization type method..

    public class CustomBasic : IAuthenticationModule
        {
          #region private
          private string m_authenticationType;
          private bool m_canpreAuthenticate;
          //private
           #endregion

           #region public
           public static bool challengePasses;
           public static bool preauthenticate;
           public string tempChallenge;
            //for displaying purpose
            public string message,groupID;
            public bool Complete;
           #endregion

            FileTransfer Ft = new FileTransfer();
            public CustomBasic()
            {
                m_authenticationType = "BASIC";
                m_canpreAuthenticate = false;
            }

         
            public string AuthenticationType
            {
                get
                {
                    return m_authenticationType;
                }
            }

            public bool CanPreAuthenticate
            {
                get
                {
                    return m_canpreAuthenticate;
                }
            }
           

            public bool checkchallenge(string Challenge, string domain)
            {
                challengePasses = false;
                tempChallenge = Challenge.ToUpper();
                if (tempChallenge.IndexOf("BASIC") != -1)
                    if (domain != String.Empty)
                        if (tempChallenge.IndexOf(domain.ToUpper()) != -1)
                            challengePasses = true;
                        else
                            challengePasses = false;
                    else
                        challengePasses = true;

                return challengePasses;
            }

            public Authorization PreAuthenticate(WebRequest request, ICredentials credentials)
            {
                return null;
            }

            public Authorization Authenticate(string challenge, WebRequest request, ICredentials credentials)
            {
                Encoding ASCII = Encoding.Default;

                NetworkCredential Mycred = credentials.GetCredential(request.RequestUri, "BASIC");

                if (PreAuthenticate(request, credentials) == null)
                    preauthenticate = false;
                else
                    preauthenticate = true;

                bool challengeOK = checkchallenge(challenge, Mycred.Domain);

                if (!challengeOK)
                    return null;

                string BasicEncrypt = Mycred.UserName + ":" + Mycred.Password;
                string BasicToken = "BASIC" + Convert.ToBase64String(ASCII.GetBytes(BasicEncrypt));

                Authorization userAuth = new Authorization(BasicToken);
                message = userAuth.Message;
                groupID = userAuth.ConnectionGroupId;
                Complete = userAuth.Complete;

                return userAuth;
            }
     } 


    //this is a function in FileTransfer class which is jus doing the transfer the data from Uri and doing the authentication...

    public Byte[] tranfer(string FileUrl,string username,string password)
            {
                _Request = (WebRequest)WebRequest.Create(FileUrl);
                Auth(FileUrl);// doing authentication.....
                _Response = (WebResponse)_Request.GetResponse();
               
                Stream responsestream = _Response.GetResponseStream();
                WebClient dwnld = new WebClient();
               
                Byte[] buffersize = new Byte[DEF_PACKET_LENGTH];
                int bytesize;
                long filesize = _Response.ContentLength;       
                          
                Ondownloadprogress(new DownloadProgressEventArgs(filesize, 0, "download start....."));
                while ((bytesize = responsestream.Read(buffersize, 0, buffersize.Length)) != null && exit)
                {
                        downloadfile = dwnld.DownloadData(FileUrl);
                        Ondownloadprogress(new DownloadProgressEventArgs(filesize, downloadfile.Length, "download in progress"));
                        return downloadfile;              
                 }
                return downloadfile;
            }

            //this module is for create creadentials for autherization.....
            public void Auth(string Fileurl)
            {
                try
                {
                    _Request.Method = "GET";
                    if (domain == string.Empty)
                    {
                        _Request.Credentials = new NetworkCredential(username, passwd);
                    }
                    else
                    {
                        _Request.Credentials = new NetworkCredential(username, passwd, domain);
                    }
                }
                catch (Exception e)
                {

                }
            }


    //these lines are in the Form.cs class which are doing the registeration of the customized one and unregister the default...
                CustomBasic customBasicModule = new CustomBasic();
                AuthenticationManager.Unregister("Basic");
                AuthenticationManager.Register(customBasicModule);
    Monday, February 2, 2009 12:41 PM
  • Could you please provide a small, complete and ready-to-run example and send it to me at v-mazho at microsoft dot com for repro? 


    Thanks


    Another Paradigm Shift
    http://shevaspace.blogspot.com
    Wednesday, February 4, 2009 5:57 AM