Category Archives: asp.net-mvc-routing

Rewrite rule from Web Forms request with Query String to MVC Action

I am trying to rewrite this Web Forms request

ourdomain.com/Members/Unlock.aspx?&Version=9.07.32&ComputerName=THING&RegistrationID=30424-59920-80950&Cals=4

to this MVC Action

ourdomain.com/Unlock?&Version=9.07.32&ComputerName=THING&RegistrationID=30424-59920-80950&Cals=4

The action signature is

[HttpGet]
public IActionResult Index(string version, string computerName, string RegistrationId, int CALs, string message = null)

My rewrite rule is in wwwroot/web.config/<system.webServer><rewrite><rules> as

<rule name="Unlock" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="Members/Unlock.aspx" />
      <conditions>
        <add input="{QUERY_STRING}" pattern="contentID=([^&amp;]+)" />
      </conditions>
      <action type="Redirect" url="Unlock" redirectType="Found" appendQueryString="True" />
</rule>

I don't get any errors but the action is not being called. This is an MVC Core project on an Azure Website.