2

I want to add defined Controller and Action to basic URL

localhost:6473  -> localhost:6473/Beta/Index

with the URL rewriting in Web.config but in some reason it doesn't work

<rewrite>
  <rules>
    <rule name="Beta_Local" stopProcessing="true">
      <match url="(localhost*)" ignoreCase="true" />
      <conditions>
        <add input="{HTTP_HOST}" pattern= "^localhost:[0-9]{4}$" negate="true"/>
      </conditions>
      <action type="Redirect" url="{R:0}/Beta/Index" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>
Andriy
  • 85
  • 1
  • 9

1 Answers1

3

The match url should not contain the domain name, but path. If you want to capture root / you need

<match url="^$" />

See http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

Also, it seems you don't need additional condition for localhost.

Complete rule could be following

<rewrite>
  <rules>
    <rule name="Beta_Local" stopProcessing="true">
      <match url="^$" /> 
      <action type="Redirect" url="/Beta/Index" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

P.S.

If you need to do it in MVC way, you could use routing

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Beta", action = "Index", id = UrlParameter.Optional }
);
user2316116
  • 6,726
  • 1
  • 21
  • 35
  • Thank's. It does work. Doing in routing is too late because Routing engine adds Beta and Index as invisible for end user but I want to have exact URL domain/Beta/Index always visible as default (for google analytics) – Andriy Apr 28 '15 at 09:11