0

I'm trying to deploy angular app in wwwroot file I don't know what to write in url below, I don't have the alias to write I suppose.

  [action type="Rewrite" url="here" /]

1 Answer 1

6

you could try below steps to create and host the angular site in iis:

first, make sure you installed node in your machine by running below command:

node --version

install Angular CLI using npm

npm install -g @angular/cli

run below command and enter to the wwwroot folder:

cd C:\inetpub\wwwroot

Create a new Angular project

ng new hello-world

Now that the basic application is ready we’ll host the application from the console using ng serve ….

ng serve

then build the application

ng build

enter image description here

enter image description here

Once the build completes successfully it publishes all the build artifacts to the dist folder.

create a site in iis and set the folder path with dist folder:

enter image description here

enter image description here

url rewrite routing rule:

This step is required to support deep-linking. Deep-linking is the capability for the user to navigate directly to a page by typing the route into the address bar instead of using the Angular routing. Deep-linking causes a problem for IIS because the URL that the user attempts to access is not known to the server and therefore the user receives a 404 response. The solution is for the server to always return the root of the application, even if the user requests a path within the application.

We’ll now add a web.config file in which we’ll have the URL rewrite rule. All requests to this web application that are not for files or folders should be redirected to the root of the application. For an web application or virtual directory under the default web site, the URL should be set to the alias, (e.g. /MyApp/). For a web site at the root of the server, the URL should be set to /.

In our case since we are using the web application HelloWorld we’ll set the url /HelloWorld/

<configuration>
<system.webServer>
  <rewrite>
    <rules>
      <rule name="Redirect all requests" 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="/HelloWorld/" />
        <!--<action type="Rewrite" url="/" />-->
        </rule>
    </rules>
  </rewrite>
</system.webServer>
</configuration>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.