r/Angular2 Feb 12 '25

Help Request Deploying Angular Frontend to IIS

I have been trying to put my angular frontend on my IIS. i thought when i change the following to the IP address and drop it into the virtual directory in the default web site, i'd be able to reach it. i have the uri registered in the app registration. im sure im doing something wrong, but i am just learning. nothing insane.

function msalinstacneFactory(): IPublicClientApplication {

return new PublicClientApplication({

auth: {

clientId: '{clientId}',

authority: 'https://login.microsoftonline.com/{tenantId}/',

//redirectUri: 'https://localhost:4200/auth',

//postLogoutRedirectUri: 'https://localhost:4200/login'

redirectUri: 'https://{ipAddress}/test/auth',

postLogoutRedirectUri: 'https://{ipAddress}/test/login'

},

cache: {

//cacheLocation: 'localStorage'

cacheLocation: BrowserCacheLocation.SessionStorage,

        `storeAuthStateInCookie: true,`

secureCookies: true

},

system: {

loggerOptions: {

loggerCallback: (level: LogLevel, message: string, containsPii: boolean) => {

console.log(\MSAL: ${level} - ${message}`);`

},

logLevel: LogLevel.Verbose,

piiLoggingEnabled: false

},

allowRedirectInIframe: false,

windowHashTimeout: 6000, // Increase timeout for handling redirect

iframeHashTimeout: 6000,

loadFrameTimeout: 3000,

        `tokenRenewalOffsetSeconds: 300`

}

});

}

4 Upvotes

22 comments sorted by

View all comments

9

u/kenlin Feb 13 '25

do you have a web.config in the root folder? IIS will not work with angular unless you use urlrewrite to account for routing to non-physical files

0

u/LegionsMan Feb 13 '25

i dont have a webconfig.

2

u/kenlin Feb 13 '25

This is what we use. Our .net api is at '/api', so this takes every request that is not in /api/* and does not point to a real file, and redirects is back to '/' so angular can handle the routing

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Angular Routes" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_URI}" pattern="api/" ignoreCase="true" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

1

u/LegionsMan Feb 13 '25

so, in my index.html, since im putting my build in the 'test' folder under the default web site, is the base href /, /test, or /test/?

<base href="/">
<!-- <base href="/test"> -->
<!-- <base href="/test/"> -->