繁体   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