beekeeper
beekeeper

Reputation: 612

Trailing slash required on Windows Server IIS for MVC area

I have an area in my ASP.NET MVC 5 application that's defined as follows. Notice the second "alias" route I'm trying to setup.

    public class MyAreaRegistration : AreaRegistration 
{
    public override string AreaName 
    {
        get 
        {
            return "My";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute(
            "My_default",
            "My/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
        );
        context.MapRoute(
            "My_Legal",
            "Legal_Stuff",
            new { controller = "Home", action = "Index" }
            );
    }
}

}

My client requires a specific URL for accessing the page, /Legal_Stuff The following URL works fine on my workstation with IIS Express launched by Visual Studio 2013:

localhost:XXXX/Legal_Stuff

However, once I place the app to a Windows 2008 R2 server (IIS), the URL gives "Page Not Found" Once I add a trailing slash, it works.

www.mysite.com/Legal_Stuff -- Page Not Found

www.mysite.com/Legal_Stuff/ -- works

However my client doesn't want the trailing slash. Is there a way to overcome this problem? I searched stackoverflow for solution and found some people recommending the IIS Rewrite module. However, none of the solutions worked for me.

Any help is greatly appreciated.

Upvotes: 0

Views: 1022

Answers (2)

beekeeper
beekeeper

Reputation: 612

Thanks for the link. Here's the solution:

   <rewrite>
        <rules>
            <rule name="Legal_Stuff" patternSyntax="ExactMatch">
                <match url="/Legal_Stuff" />
                <action type="Rewrite" url="/LegalStuff/" />
            </rule>
        </rules>
    </rewrite>

Upvotes: 0

mgilboa
mgilboa

Reputation: 68

URL Rewrite IS the more efficient way to do this, but tends to be more technical demanding.

Here is a friendly article that can help you with that: http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

Another easier way it so to redirect in your IIS Manager -> Click on your website -> Use the HTTP Redirect feature to redirect to your website to the same website containing a containing slash.

URL Example : www.mysite.com/Legal_Stuff/

Keep in mind that the server will redirect to your address and will result in response 302 in case someone would try to access your website.

Upvotes: 2

Related Questions