【问题标题】:Quasar with Asp.NET Core WebApi IIS publish 403 errorQuasar with Asp.NET Core WebApi IIS 发布 403 错误
【发布时间】:2021-04-05 07:58:56
【问题描述】:

在开发阶段,quasar项目可以在IIS虚拟应用下托管和运行。发布时,从dist文件夹复制文件到iis根目录,index页面正常显示,但是使用webapi url发起httppost请求时出现403错误。我使用了 IIS UrlRewrite 组件。似乎与 webapi 请求相关的问题与 urlrewrite 冲突。

  1. web.config 文件包含 url 重写规则
     <?xml version="1.0" encoding="UTF-8"?>
     <configuration>
      <system.webServer>
       <rewrite>
        <rules>
         <rule name="Handle History Mode and custom 404/500" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
           <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
           <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.html" />
         </rule>
        </rules>
       </rewrite>
     <httpErrors> 
       <remove statusCode="404" subStatusCode="-1" /> 
       <remove statusCode="500" subStatusCode="-1" />
       <error statusCode="404" path="/survey/notfound" responseMode="ExecuteURL" /> 
       <error statusCode="500" path="/survey/error" responseMode="ExecuteURL" />
      </httpErrors>
     </system.webServer>
    </configuration>
  1. startup.cs 文件包含控制器路由模式
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
    
        app.UseRouting();
        app.UseSpaStaticFiles();
        app.UseAuthorization()
            .UseCors("AllowAll");
    
    
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "api/{controller=Home}/{action=Index}/{id?}");
        });
        app.UseSpa(spa =>
       {
           spa.Options.SourcePath = "ClientApp";
    
           if (env.IsDevelopment())
           {
               spa.UseVueCli(npmScript: "serve", forceKill: true);
           }
       });
    }
  1. IIS 403 错误 当有 webapi 请求时,就会发生错误...

http://localhost/webdemo2/api/wf/QueryProcessRoles

有一篇文章对将quasar项目部署到IIS很有用,但是403错误仍然存​​在。有人可以在这里找到解决方案吗?谢谢

https://forum.quasar-framework.org/topic/3004/deploy-quasar-application-in-iis

【问题讨论】:

    标签: vue.js asp.net-core webapi quasar


    【解决方案1】:

    403错误的原因有很多,可以尝试以下方法解决问题:

    1.如果没有给文件夹正确的权限,就会出现403错误页面。您需要将 IIS_IUSRS 安全权限分配给您分配的 Web 文件夹。

    右键单击您在 IIS 中为 Web 访问分配的文件夹,选择“属性”,然后转到“安全”选项卡。在顶部框中,“组或用户名”,打开“编辑...”,您很可能无法在列表中细化 IIS_IUSRS;打开,“添加..”,在最底部的框中​​,“输入要选择的对象名称(示例):”输入 IIS_IUSRS,单击确定并确保在权限窗口中,您已允许,读取并执行,列出文件夹内容和阅读

    2.请检查您是否设置了default document

    【讨论】:

      猜你喜欢
      • 2018-10-30
      • 1970-01-01
      • 1970-01-01
      • 2016-07-27
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      • 2021-01-30
      • 2017-05-03
      相关资源
      最近更新 更多