Noah
Noah

Reputation: 9

remove extension in URL on an iis server

I have pages set up with razor code to use a consistent layout on every page. I don't want the pages url to display with the .cshtml tag How can I do this. I use JQuery, JavaScript, HTML, CSS, ASP.net (web Pages Logic)

EX URL; http:// www.site.com/page.htm

I am new to ASP and server side stuff.

@{
    Layout = "~/Shared/_Layout1.cshtml"; <!--i use a _PageStart.cshtml that contains this line for dry purpose-->

    Page.title = ""; @*add pages title here*@
}

<!--If you want to add Page specific stylesheets Link them here with HTML tags-->
@section ExtraHeadContent {

}


@section NavBarLinks {
    <!--Enter links here for the top navigation bar <a class="topnav-link" href="~/index.html">| Home</a> -->
}

<!--Enter the Pages HTML content here. This will be displayed in the white content div-->

If there are any relevant pages or discussions you've found in the past please share.

Upvotes: 0

Views: 1247

Answers (1)

Mike Brind
Mike Brind

Reputation: 30120

The built in routing system within the ASP.NET Web Pages framework allows you to omit the file extension altogether. If you request www.yourdomain.com/YourPage (where YourPage represents a file called YourPage.cshtml), it should work by default. You can read more about it here: http://www.mikesdotnetting.com/Article/165/WebMatrix-URLs-UrlData-and-Routing-for-SEO.

As for replacing the file extension with .htm, I'm not sure that you hope to achieve by doing that. It won't improve SEO. However, one option would be to use a Nuget package called WebPageRouteHandler. I've written about that too: http://www.mikesdotnetting.com/Article/187/More-Flexible-Routing-For-ASP.NET-Web-Pages. Mapping each file individually could be a pain, but you could generate the routes dynamically from a database or from looping through the physical files to reduce the code required.

Upvotes: 1

Related Questions