i'm struggling issue in asp.net core & angular 2 application, works great in development, when publishing iis , configuring iis asp.net core fails load required stylesheets , scripts.
i redirect requests don't map api routing index.html returning virtualfileresult
. index.html has
<!doctype html> <html> <head> <title>data platform</title> <meta name="description" content="data platform" /> <meta charset="utf8" /> <base href="/" /> <link rel="stylesheet" href="lib/css/vendors.css" /> <link rel="stylesheet" href="platform/content/css/base.css" /> <link rel="stylesheet" href="platform/content/css/bootstrap-overrides.css" /> <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" /> <script src="lib/vendors.js"></script> <script> system.config({ packages: { "/platform/": { defaultextension: "js" } } }); system.import("/platform/boot"); </script> </head> <body> <data-platform>initializing...</data-platform> </body> </html>
the startup.cs
configuration pretty basic:
app.useiisplatformhandler(); if (string.equals(env.environmentname, "development", stringcomparison.ordinalignorecase)) { app.usedeveloperexceptionpage(); } app.usefileserver(false); app.usestatuscodepages(); app.usemvc(routebuilder => { routebuilder.maproute( name: "api", template: "api/{controller}/" ); routebuilder.maproute( name: "client passthrough", template: "{*any}", defaults: new { controller = "clientpassthrough", action = "index" } ); });
the clientpassthrough controller action basic:
public iactionresult index() { return new virtualfileresult("~/index.html", "text/html"); }
works fine in development, fails miserably in production. i've tried changing base href ~/
point subsequent urls proper application root instead of server root... still can't seem find css files or scripts in /wwwroot/
folder.
if using .net core razor can add following code set base url url of iis app publishing to.
<base href="@(url.content("~"))" />
this code should go in <head>
below <title>
element.
then when reference root use
<link rel="stylesheet" href="lib/css/vendors.css" />
without slash in front of path. worked me.
if try use <base href="/" />
or <base href="~/" />
, iis won't know because tilde has no meaning unless gets parsed .net opposed served text in page.
hope helps someone.
Comments
Post a Comment