簡體   English   中英

發布到服務器 iis 時,Asp.net web api 返回 404

[英]Asp.net web api return 404 when publish to server iis

我想玩 asp.net web api。 使用簡單的網站,然后我創建 asp.net webform 類型的 web api 並在我的本地機器上運行它,然后我嘗試發布這個項目而不自定義以檢查我的 iis 服務器。 但它返回“403 - Forbidden: Access is denied”。

http://localhost:51845/

在此處輸入圖片說明

這是我的設置 iis 與我機器中的相同項目

在此處輸入圖片說明

服務器:8080(我將我的 ip 服務器替換為服務器)

在此處輸入圖片說明

然后我的機器和服務器機器有同樣的錯誤,有什么問題? 請幫忙。 謝謝

備注此項目身份驗證 -> 沒有像這樣的身份驗證

在此處輸入圖片說明

我的網絡配置代碼

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301879
  -->
<configuration>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0"/>
    <add key="webpages:Enabled" value="false"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
  </appSettings>
  <!--
    For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.5" />
      </system.Web>
  -->
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime/>
    <pages controlRenderingCompatibilityVersion="4.0"/>
  </system.web>
  <system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
      <remove name="OPTIONSVerbHandler"/>
      <remove name="TRACEVerbHandler"/>
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
  1. 按win+R
  2. 寫“InetMgr”然后按回車鍵
  3. 右鍵單擊您的站點,然后單擊“EditBindings”
  4. 將端口更改為 51845 然后保存
  5. 將您的項目發布到站點位置(右鍵單擊您的站點並單擊“瀏覽”)
  6. 瀏覽http://localhost:51845/

如果您需要表單身份驗證,但該模塊未運行,IIS 只會給出 403 錯誤,因為它無法為您提供應用程序所需的身份驗證類型。

因此,您可以嘗試在應用程序的 Web.config 下設置“為所有請求運行所有托管模塊”選項

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"></modules>
    <handlers>
      <remove name="UrlRoutingHandler"/>
    </handlers>
  </system.webServer>

你可以檢查你發布APP的文件夾是否有IIS權限。 您可以嘗試在文件夾的安全屬性中向“所有人”授予權限。

如果沒有,請檢查 ISS 上 WebAPI 的 web.config 並仔細檢查身份驗證值和配置。

發布時,如果您選擇合並所有輸出單個程序集,則必須設置一個沒有空格或特殊字符的名稱我遇到了這個錯誤,我可以通過這個解決方案修復它祝你好運

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM