0

This seems pretty simple, but for the life of me I can't figure it out.

Using ASP.NET Classic (ie non-MVC), say I have a website www.foo.com that has an /api folder, and in that folder is the file api.aspx (i.e. you hit www.foo.com/api/api.aspx)

How can I set things up (either via Web.config rewrite or via MapPageRoute() in Global.asax.cs) so that www.foo.com/api

  1. hits /api/api.aspx not /api/Default.aspx
  2. doesn't show api.aspx in the browser's URL box (I just want to see either www.foo.com/api or www.foo.com/api/)

I would have thought that this would work:

routes.MapPageRoute("ApiRoute","api","~/Api/Api.aspx");

but it doesn't... I still hit /api/Default.aspx

EDIT: I also want to support /abc/abc.aspx and /thing/thing.aspx, mostly so when I have these pages open in the IDE they're not all named "Default.aspx" and I can't quickly see which page is which.

dlchambers
  • 3,511
  • 3
  • 29
  • 34
  • The easiest way to get this to work would be to set your Default Document to Api.aspx in IIS. – Khan Feb 27 '15 at 17:16
  • Please see my edit; I want multiple pages, so I don't want the global default doc to be named api.aspx. – dlchambers Feb 27 '15 at 18:12

1 Answers1

0

I've created a small demo project. Each folder I want to set a specific default document I add a web.config file.

project structure

Project Structure

Each web.config file defines a default file for it's folder.

web.config in folderA

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <defaultDocument enabled="true">
      <files>
        <clear/>
        <add value="a.aspx"/>
      </files>
    </defaultDocument>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

Accordingly for folderB

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <defaultDocument enabled="true">
      <files>
        <clear/>
        <add value="b.aspx"/>
      </files>
    </defaultDocument>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

ATTENTION

When I did some tests in my development webServer it did not work. But when I published my project to my local IIS instance it did work out all right.

local IIS deployment

local IIS deployment

Pilgerstorfer Franz
  • 8,303
  • 3
  • 41
  • 54