ASP.NET 5 and Angular Routing not working with dnx rc1

Hi I have a project built in ASP.NET 5 (dnxcore50 and dnx451). It serves requests for my AngularJS scripts. When I built the project, I used Microsoft beta dependencies and used the rewrite rule to send all requests to index.html, and so my angular routing will work fine. But today I needed to switch to rc1 dependencies, and now my rewrite is not working, and I just get 404 on my route. These new libraries have added these weird lines of code to my web.config

  <handlers>
  <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" forwardWindowsAuthToken="false" startupTimeLimit="3600" />

Is there a way in which I can configure my routing to work with angular, for example, if I go to localhost / shop, it will redirect it to index.html, and my angular routing will take.

0
source share
3 answers

I am in a similar setup, and I have a Customize in Startup.cs,

    app.UseDefaultFiles();

    app.UseStaticFiles();

    app.UseIISPlatformHandler();

and the rewrite rule in system.webServer in web.config, it is necessary to have a web api and index.html angular application available:

    <rewrite>
      <rules>
        <!--Redirect selected traffic to index -->
        <rule name="Index Rule" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_URI}" matchType="Pattern" pattern="^/api/" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" />
        </rule>
      </rules>
    </rewrite>

You may need something similar too with your own rules.

+3
source

I think there is a better way than using URL rewriting in the routing setup (so there is no need to rewrite the URL at all). For instance. I have done this:

    app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "api",
                template: "api/{controller}/{action}");

            routes.MapRoute(
                name: "angular",
                template: "{*url}",
                defaults: new {controller = "Home", action = "Index"},
                constraints: new {url = new DoesNotContainConstraint(".", "api/") });                
        });

, /api , - Index. DoNotContainConstraint, , api URL- , .

0

If you want to use ASP.NET 5 / ASP.NET Core with IIS, you need to install the HttpPlatformHandler. Here 's a step-by-step guide showing how to install the Http Platform Handler, configure IIS, and publish the APS.NET Core application for IIS.

0
source

All Articles