C#Web服务返回403错误

时间:2015-04-09 17:25:40

标签: c# asp.net authentication

当外部应用程序调用时,我有一个使用https返回403错误的Web服务。直接导航到服务按预期工作。我相信我已经通过了当前的crendentials并调整了web.config以按预期工作。然而,它仍然返回403.除非它是一个IIS设置,我才难倒。

网络配置:

            <jsonSerialization maxJsonLength="5000"/>
        </webServices>
    </scripting>
</system.web.extensions>
<appSettings/>

<connectionStrings>
    <add name="xxxxx"/>
</connectionStrings>
<system.web>
    <!-- 
        Set compilation debug="true" to insert debugging 
        symbols into the compiled page. Because this 
        affects performance, set this value to true only 
        during development.
    -->
    <compilation debug="true" targetFramework="4.0">
    </compilation>
    <!--
        The <authentication> section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    -->
<authorization>
    <deny users="?"/>
    <allow users = "*" />
</authorization>
    <authentication mode="Windows"/>
    <!--
        The <customErrors> section enables configuration 
        of what to do if/when an unhandled error occurs 
        during the execution of a request. Specifically, 
        it enables developers to configure html error pages 
        to be displayed in place of a error stack trace.

    <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
        <error statusCode="403" redirect="NoAccess.htm" />
        <error statusCode="404" redirect="FileNotFound.htm" />
    </customErrors>
    -->
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web>
<!-- 
    The system.webServer section is required for running ASP.NET AJAX under Internet
    Information Services 7.0.  It is not necessary for previous version of IIS.
-->

代码块:

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
                       "url");
                    // Set the Method property of the request to POST.
                    request.Method = "POST";
                   // request.UseDefaultCredentials = true;
                    //if (request.Proxy != null)'
                    request.Credentials = System.Net.CredentialCache.DefaultCredentials;
                        request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
                    request.Accept = "*/*";
                    request.UserAgent = "Mozilla/5.0";
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.ContentLength = 0;
                    // Get the response.
                    WebResponse response = request.GetResponse();

0 个答案:

没有答案