In der SPA -Anwendung können 404 Seiten nicht eingerichtet werdenC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 In der SPA -Anwendung können 404 Seiten nicht eingerichtet werden

Post by Anonymous »

Ich habe eine API -Anwendung mit Angular auf der Client -Seite und ASP.NET -Kern im von IIS servierten Backend. Ich benutze auch SAML2, um sich zu authentifizieren. Mein Setup ist so: < /p>
Client -Seite, Angualr.json -Datei: < /p>

Code: Select all

Project > MyApp > architect > build > options > index: src/root.html
< /code>
Program.cs
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseContentRoot(System.IO.Directory.GetCurrentDirectory())
.UseIIS()
.UseStartup()
.UseNLog()
.Build();
host.Run();
}
< /code>
startup.cs in der konfigurieren Methode < /p>
app.UseHttpsRedirection();
app.UseHsts();
app.UsePathBase("/api");
app.UseDefaultFiles();
app.UseStaticFiles(new StaticFileOptions()
{
OnPrepareResponse = context =>
{
context.Context.Response.Headers.Add("Cache-Control", "no-cache, no-store");
context.Context.Response.Headers.Add("Expires", "-1");
}
});

if (!env.IsDevelopment())
{
app.UseSpaStaticFiles();
}

app.UseRouting();
app.UseCors();
app.UseSaml2();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});

app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";

if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
});
< /code>
und in der Methode configureServices: < /p>
services.AddSaml2();

// In production, the Angular files will be served from this directory
if (!Environment.IsDevelopment())
{
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
}
Aktuelles Verhalten:
Wenn die App serviert wird, wird es am Root so angezeigt. /> Problem:
Ich versuche, eine 404 -benutzerdefinierte Seite in meinem IIS einzurichten, wenn ein Controller, der nicht existiert, aufgerufen wird, aber das Verhalten, wenn ich so etwas versuche: https: ///root.html#/bogus, der URL wird sofort auf den vorherigen URL zurückgeführt, aber es gibt einen Fehler in der Konsole von Chrome:

Code: Select all

ERROR oe: NG04002: 'bogus'
at Wue.noMatchError (https://myserver/main.js:1:385012)
at https://myserver/main.js:1:385814
at https://myserver/main.js:1:347833
at Sn._error (https://myserver/main.js:1:17455)
at Sn.error (https://myserver/main.js:1:12087)
at Sn._error (https://myserver/main.js:1:12327)
at Sn.error (https://myserver/main.js:1:12087)
at Sn._error (https://myserver/main.js:1:12327)
at Sn.error (https://myserver/main.js:1:12087)
at Sn._error (https://myserver/main.js:1:12327)
< /code>
Ich habe in die Oberseite gesucht und es gibt eine Reihe von Aufrufen dieser Methode: < /p>
        error(n) {
this.isStopped ? ve(function gu(t) {
return _u("E", void 0, t)
}(n), this) : (this.isStopped = !0, this._error(n))
}
Ich konnte nicht herausfinden, welcher meiner Einstellungen Main.js aufweist, um den Zielfehler zu bewältigen und wie ich stattdessen zu mir zurückkehren kann, damit ich meine benutzerdefinierte 404 -Seite anzeigen kann?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post