简体   繁体   English

带有Angular的.NET Core:如何配置IIS以HTML5模式进行URL重写?

[英].NET Core with Angular : How do I configure IIS for URL Rewriting in HTML5 mode?

I have built an angular 6 application with .Net core 2.1 and deployed to azure server on IIS web server. 我已经使用.Net core 2.1构建了一个angular 6应用程序,并将其部署到IIS Web服务器上的azure服务器。 The routing is working fine on localhost when refresh, but not working on azure server. 刷新时,路由在本地主机上工作正常,但在azure服务器上不工作。 I checked angular deployment guideline and added following code in web.config file 我检查了角度部署准则,并在web.config文件中添加了以下代码

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Angular Routes" 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>
</system.webServer>

Now, I got into new problem. 现在,我遇到了新问题。 All the files now contains index.html content, instead of their respective file content. 现在,所有文件都包含index.html内容,而不是它们各自的文件内容。 在此处输入图片说明 在此处输入图片说明

What am I missing here? 我在这里想念什么? Do I need to make any changes to kestrel server 我是否需要对Kestrel服务器进行任何更改

This section of the angular guide does not apply to ASP.NET Core hosted Angular applications. 角度指南的本部分不适用于ASP.NET Core托管的Angular应用程序。 Only for non-.NET or classic ASP.NET websites, a rewrite module definition is needed. 仅对于非.NET或经典ASP.NET网站,才需要重写模块定义。

If you started your application based on ASP.NET Core's templates for angular or SPAs, you have rewriting / SPA fallback routes set up already. 如果您基于针对角度或SPA的ASP.NET Core的模板启动应用程序,则您已经设置了重写/ SPA后备路由。

I suggest starting from applications created with dotnet new angular -o MyAngularApp our using VS' angular templates (both use the same template packages). 我建议从使用dotnet new angular -o MyAngularApp创建dotnet new angular -o MyAngularApp应用程序开始,我们使用VS'的角度模板(两者都使用相同的模板包)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为URL重写Anuglar应用程序配置Wildfly - How do I configure Wildfly for URL Rewriting an Anuglar application 如何使用IIS appsettings.json在dotnet核心中配置Angular 6 URL重写 - How to configure Angular 6 URL rewrite in dotnet core using IIS appsettings.json 如何在这个 angular 2 示例上使用 HTML5 模式? - How to use HTML5 mode on this angular 2 sample? 如何在 Startup.cs 中使用 ASP.NET 核心的 Angular SPA 的参数管理 HTML5 路由回退? - How to manage HTML5 route fallback with parameter for Angular SPA with ASP.NET Core in Startup.cs? 如何在带有Docker容器的HTML5模式下部署angular2应用 - How to deploy angular2 app with HTML5 Mode with docker container 如何解决ok:Angular 5和.NET Core的错误响应? - How do I solve ok: false response with Angular 5 and .NET Core? 在 angular 5 路由中看不到 html5 页面,在仪表板的 url i 中 - Dont see the html5 page in angular 5 routing,in url i in the dashboard 如何使用IIS发布和运行asp.net core 1和angular 2应用程序? - How to publish and run asp.net core 1 & angular 2 application with IIS? 如何在IIS上部署Angular和.NET Core Web API? - How To Deploy Angular And .NET Core Web API On IIS? 如何在 IIS 上使用 Angular 12 部署 ASP.NET Core 6 应用程序 - How to deploy an ASP.NET Core 6 application with Angular 12 on IIS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM