刷新浏览器时,带有Angular 4的.Net Core:404错误 [英] .Net Core with Angular 4 : 404 error when I refresh the browser

查看:80
本文介绍了刷新浏览器时,带有Angular 4的.Net Core:404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用.Net core 2.0,Visual Studio 2017构建了一个angular 4应用程序,并将其部署到IIS Web服务器上的生产服务器上.刷新时,路由在localhost上工作正常,但无法实时运行.我在web.config文件中的IIS的stackoverflow中看到了一些答案.但是我的项目结构下没有web.config文件.我可以手动添加它或如何解决它.

I have built an angular 4 application with .Net core 2.0, visual studio 2017, and deployed to production server on IIS web server. The routing is working fine on localhost when refresh,but not working on live. I saw some answers in stackoverflow for IIS in web.config file. But I don't have web.config file under my project structure. can I add it manually or how can I fix it.

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

这是我的app.routing文件

Here is my app.routing file

   const appRoutes: Routes = [
  { path: '', redirectTo: 'admin-dashboard', pathMatch: 'full' },
  { path: 'login', component: LoginComponent },
  { path: 'forgotpassword', component: ForgotPasswordComponent },
  { path: 'user-dashboard', component: DashboardComponent, canActivate: [AuthGuard] },
 { path: 'notifications', component: NotificationsComponent, canActivate: [AuthGuard] },
 {
path: 'admin-dashboard', component: AdminDashboardComponent, canActivate: [AuthGuard],
children: [
  { path: '', component: ChairmanMessagesComponent, canActivate: [AuthGuard]},
  { path: 'quotes', component: QuotesComponent, canActivate: [AuthGuard] },
  { path: 'users', component: UsersComponent, canActivate: [AuthGuard] },
  { path: 'notifications', component: AdminNotificationsComponent, canActivate: [AuthGuard] },
]

}, ];

 export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

请让我知道.

推荐答案

在后端(服务器端),只需将所有(404)错误/无法识别的请求映射到您的索引(包括所有角度构建脚本),然后返回索引.在前端,您可以获取所需的内容.它映射到所需的页面.

In back-end (server side) just map all (404) error/unrecognized requests to your index (which includes all angular build scripts).then it returns the index. In front-end, u can get what u need.It maps to the page which u need.

例如:- 在Spring Boot后端,这是一个示例答案

这篇关于刷新浏览器时,带有Angular 4的.Net Core:404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆