Derive MVC route parts from a request URI¶
Derive ASP.NET MVC-style route segments from a request URI, triggered when a consuming web layer needs the application, page, or controller/action name from the current request URL*.
| Field | Value |
|---|---|
| Operation ID | OP-029 |
| Trigger | A consuming web layer needs the application, page, or controller/action name from the current request URL* |
| Inputs | Uri |
| Outputs | string |
| Primary components | UriExtensions.ApplicationName`, `PageName`, `ControllerAndActionName |
| Entry point | Common/SAIF.Common/Extensions/UriExtensions.cs |
Steps¶
ApplicationName: if the URI is null or has fewer than 2 segments, returnstring.Empty; otherwise return segment 1 with/removed — the IIS virtual-directory / application name. (BR-068)PageName: guard withEnforce.ArgumentNotNull(uri, "uri")(throws on null, unlike the other two members), then return segment 2 with/removed, or the literal "Index" when there are 2 or fewer segments. (BR-069, BR-039)ControllerAndActionName: seed the result with the default "Home/Index" and return that immediately if the URI is null. (BR-070)- With more than 3 segments, concatenate segments 2 and 3 (controller + action, each retaining its trailing
/). (BR-070) - With exactly 3 segments, concatenate segment 2 with the literal "Index" — the default action. (BR-070)
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start(["Caller requests<br>a route part"]) --> D1{"ApplicationName: URI null<br>or fewer than 2 segments?"}
D1 -->|Yes| S1a([Return empty string])
D1 -->|No| S1b(["Return segment 1<br>minus '/'"])
S1a --> S2
S1b --> S2["PageName: guard uri<br>not null (throws if null)"]
S2 --> D2{"PageName: 2 or<br>fewer segments?"}
D2 -->|Yes| S2a(["Return literal 'Index'"])
D2 -->|No| S2b(["Return segment 2<br>minus '/'"])
S2a --> S3
S2b --> S3["ControllerAndActionName: seed<br>result as 'Home/Index'"]
S3 --> D3{"URI is null?"}
D3 -->|Yes| S3a(["Return 'Home/Index'"])
D3 -->|No| D4{"More than<br>3 segments?"}
D4 -->|Yes| S4(["Return segment 2<br>+ segment 3"])
D4 -->|No| D5{"Exactly<br>3 segments?"}
D5 -->|Yes| S5(["Return segment 2<br>+ literal 'Index'"])
D5 -->|No| End(["Return default<br>'Home/Index'"])
Related documentation¶
Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
Common/SAIF.Common/Extensions/UriExtensions.cs