Setting up Angular deep linking on IIS

前端 未结 2 1082
一向
一向 2021-01-21 05:28

I\'m trying to configure an Angular/ASP.NET 5 application on IIS to support deep linking, so that a URL such as domain.com/article/title-slug works

I\'ve added the follo

相关标签:
2条回答
  • 2021-01-21 05:34

    Was running into the same issue. After tinkering with a number of things, changing the base href tag in the index.html file to the fully qualified Url is what finally fixed it for me.

    Before:

    <!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>
    

    After:

    <!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>
    

    My Rewrite rule:

    <?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>
    

    My use case was setting up an application under the default website, so your setup might be different.

    0 讨论(0)
  • 2021-01-21 05:40

    I ended up fixing this by scrapping the URL rewrite module and handling this in code:

            app.Run(async (context) =>
           {
               context.Response.ContentType = "text/html";
               await context.Response.SendFileAsync(Path.Combine(env.WebRootPath, "index.html"));
           });
    
    0 讨论(0)
提交回复
热议问题