You can create short, easy-to-type URLs for users of an MDriven Turnkey application hosted in Azure App Service or local IIS by adding an IIS rewrite rule to the Turnkey Web.config file.
For example, a visitor can enter:
https://app.world.se/su?vSeekParam=bio
IIS redirects the visitor to a Turnkey DisplayWithVariables URL such as:
The browser ends on the Turnkey URL, which opens the specified ViewModel and supplies the variables that the view uses. In this example, vSeekParam receives bio and can be used as the search text.
When to use an IIS rewrite rule
Use this approach when you want a fixed, public shortcut such as /su to redirect before Turnkey handles the request. The rule is configured in the web server, not in the model.
Use RedirectView when you need model-driven handling of invalid URLs or need to inspect the requested URL and choose a destination using application logic. RedirectView receives RawURL and ErrorCode; it is therefore suited to error handling and conditional shortcuts.
| Requirement | Use |
|---|---|
Redirect a known short path such as /su to one known Turnkey URL
|
IIS rewrite rule in Web.config
|
| Handle an unknown or invalid URL and decide what to do in the application | RedirectView |
| Show a startup page while a .NET Core Turnkey application loads | StartupViewTemplate |
Add a short URL redirect
- Locate the Turnkey application's
Web.config. For Azure App Service deployment, Turnkey is deployed undersite\wwwroot; see HowTos:Install MDriven Server and Turnkey on Microsoft Azure. For local hosting, edit theWeb.configfor the IIS application that hosts Turnkey. - Open
Web.configand find the<system.webServer>section. - Add a
<rewrite>section inside<system.webServer>. If the file already has a<rewrite>section, add the new<rule>inside its existing<rules>element instead of creating a second section. - Replace the example host name, ViewModel name, object identifier, and variable names with values used by your application.
- Deploy or save the changed file, then request the short URL in a browser.
Example configuration
The following rule redirects the relative path su to the PublicSeeker view. It also preserves incoming query-string values.
<system.webServer>
<applicationInitialization doAppInitAfterRestart="true" skipManagedModules="true" remapManagedRequestsTo="Startup.htm">
<add initializationPage="Turnkey/Index" />
</applicationInitialization>
<rewrite>
<rules>
<rule name="Redirect subdir" stopProcessing="true">
<match url="su" />
<action
type="Redirect"
url="https://app.world.se/Turnkey/DisplayWithVariables?view=PublicSeeker&id=22!1212&vSeekNow=true"
appendQueryString="true"
redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
The applicationInitialization section is shown only to establish where the rewrite section can be placed. It is not required by the redirect rule itself. If your file does not use application initialization, place <rewrite> anywhere inside <system.webServer>.
How the example works
| Configuration part | Meaning |
|---|---|
<match url="su" />
|
Matches the relative request path /su for this IIS application.
|
type="Redirect"
|
Sends an HTTP redirect to the browser. The browser then requests the Turnkey destination URL. |
view=PublicSeeker
|
Names the ViewModel that Turnkey opens through DisplayWithVariables.
|
id=22!1212
|
Supplies the root-object identifier used by this example ViewModel. Replace it with the identifier required by your view. |
vSeekNow=true
|
Supplies a variable to the ViewModel. In this example, it directs the view to perform its search. |
appendQueryString="true"
|
Appends query-string parameters supplied on the short URL to the destination URL. |
redirectType="Found"
|
Uses the IIS Found redirect type.
|
Pass values from the short URL
With appendQueryString="true", values provided by the visitor remain available after the redirect.
For this request:
https://app.world.se/su?vSeekParam=bio
IIS redirects to a URL that includes both the fixed values from the rule and the incoming value:
To use this pattern, the target ViewModel must define and use the variable named in the URL. In the example, vSeekParam is the variable that receives bio.
Verify the redirect
- Request the short path without parameters, for example
https://app.world.se/su. - Confirm that the browser is redirected to
Turnkey/DisplayWithVariablesand that the intended ViewModel opens. - Request the path with a parameter, for example
https://app.world.se/su?vSeekParam=bio. - Confirm that the destination ViewModel receives the value and performs the expected search or other action.
Important considerations
- The rule matches the relative path configured in
match. The example matchessu, not the full domain name or a URL beginning with/. - Replace
https://app.world.sewith the public URL for your Turnkey application. Do not leave the example domain in a production rule. - Replace
PublicSeeker,22!1212,vSeekNow, andvSeekParamwith names and values that exist in your application. - Because this is a browser redirect, the Turnkey destination URL is visible after the redirect. This rule makes the entry URL short; it does not keep the destination path hidden.
- If you use OpenID Connect, configure the identity provider callback separately as described in Documentation:OpenID config. A shortcut redirect is not an OpenID callback URL.
- For Azure deployment and application layout, follow HowTos:Install MDriven Server and Turnkey on Microsoft Azure. For Azure-specific hosting background, see Documentation:Microsoft Azure.
