Asp.net MVC adding application name to URL

Asked

Viewed 1,432 times

12

I have a domain on a shared server and within it I have some subfolders that are set as applications on IIS 7. Within the main domain I created subdomains that redirect to applications/folders.

Ex:

  • www.dominio.com.br
  • Subdomain.dominio.com.br

It worked perfectly with an Asp.net Web Forms application. But I updated the technology to MVC and when I access the application by the url "Subdomain.dominio.com.br" MVC is adding the name of the subfolder/application to the url by clicking on a link action.

Ex:

  • Subdomain.dominio.com.br/Domain/Controller/Acction

and so the application doesn’t work. only works if I access the application by the url: "www.dominio.host.com.br/App/Controller/Acction" and still have to change some requests in the code.

would like the url to appear only:

  • Subdomain.dominio.com.br/Controller/Acction

I have tried several route options in the code and also tested Rewrite URL as below but nothing worked.

<system.webServer>
.
.
.
<rewrite>
  <rules>
    <rule name="Remove Virtual Directory">
      <match url=".*" />
      <action type="Rewrite" url="{R:0}" />
    </rule>
  </rules>
</rewrite>
</system.webServer>

Suggested Update

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
  • Have you checked if the directory where the MVC application is even as an application? If possible update your question with your routing rules (Registerroutes)

  • Yes, the directory is as an application. I updated, but this is by default MVC

1 answer

2


Try adding the following change to "Global.asax".

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "subdominio_1",
            "Subdominio/{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

        //Mantenha as outras rotas
    }
  • 1

    thanks, this way is the way I wanted to avoid, but I ended up leaving the name of the application at the end anyway, no way, being shared server the rewriting rules of the own hosting do not allow it to appear without the name of the folder, I ended up making the manual adjustments in the project so I wouldn’t have problems with errors like "404"... but thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.