3

My Angular web application installs in IIS under an existing web site through an MSI installer. Since its not my server, I cannot require URL Rewrite to be installed.

I came up with a simple solution to just drop a Global.asax file (without code behind) in the app folder.

I simply coded a really basic redirect to bring the user back to index.html if he hits Refresh.

The Gobal.asax is like this:

<%@ Application Language="C#" %>

<script runat="server">

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        var httpApp = sender as HttpApplication;
        string path = httpApp.Context.Request.Path;

        if (path.StartsWith(@"/WebApp/") && path.ToLower() != @"/WebApp/Index.html")
        {
            HttpContext.Current.Response.Redirect("/TimeSpent.DataService/WebApp/Index.html");
        }
    }

</script>

Its not an ideal solution but prevents users to get stuck with a 404.

Does someone has a clean idea to improve this and bring back the user to the route he was trying to reload?

Many thanks

jjslagace
  • 232
  • 1
  • 7

0 Answers0