我试图在IIS上配置一个角/ASP.NET 5应用程序,以支持深度链接,这样一个URL (如domain.com/ that /title-slug)就可以工作了。
我使用IIS重写模块将以下代码添加到我的web.config中:
<rewrite>
<rules>
<rule name="redirect all" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="wwwroot/index.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>我的问题是,我的网站不再加载,我有一个空白的屏幕,没有任何在网络选项卡和没有来源。
我的inetpub\site\文件夹是dotnet核心发布文件夹的根目录,我在inetput\site\wwwroot中有角构建资产。
我的基本href是= "/“,没有重写代码一切都很好。
最后,我尝试将重写URL更改为
<action type="Rewrite" url="/index.html" appendQueryString="true" />但之后我开始发现错误:
inline.f137c7f1f4e2a52a2fb9.bundle.js:1 Uncaught SyntaxError: Unexpected token <
polyfills.25e42e2a7a0746e9ff75.bundle.js:1 Uncaught SyntaxError: Unexpected token <
main.0d9f8e7be2ccd1472551.bundle.js:1 Uncaught SyntaxError: Unexpected token <发布于 2018-01-19 06:36:39
最后,我取消了URL重写模块,并在代码中处理了这个问题,从而修复了这个问题:
app.Run(async (context) =>
{
context.Response.ContentType = "text/html";
await context.Response.SendFileAsync(Path.Combine(env.WebRootPath, "index.html"));
});发布于 2018-02-27 02:10:03
也遇到了同样的问题。在修改了许多东西之后,将index.html文件中的基href标记更改为完全限定的Url,最终为我修复了它。
以前:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MySubApp</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<mu-root></mu-root>
<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="scripts.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
</html>后:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MySubApp</title>
<base href="http://MyUrl.com/MySubApp/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<mu-root></mu-root>
<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="scripts.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
</html>我的重写规则:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="test" enabled="true" 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="/MySubApp/" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>我的用例是在默认网站下设置一个应用程序,所以您的设置可能有所不同。
https://stackoverflow.com/questions/48332488
复制相似问题