To change the root path of your ASP.NET MVC application or the URL path in IIS, you can follow different approaches depending on your requirements.

  1. Change the Application Root Path in ASP.NET MVC: In an ASP.NET MVC application, you can change the root path by modifying the RouteConfig.cs file. By default, the root path is set to "/" in the RegisterRoutes method. You can update the MapRoute method to specify a different URL pattern as the root path.

    csharp
    public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "your-root-path/{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); }

    Replace "your-root-path" with the desired URL segment to serve as the root path for your application.

  2. Change the URL Path in IIS: If you want to change the URL path at the IIS level, you can set up a URL rewrite rule in the web.config file of your ASP.NET MVC application. The URL rewrite rule will redirect incoming requests from the original URL path to the desired new URL path.

    xml
    <configuration> <system.webServer> <rewrite> <rules> <rule name="ChangeRootPath" stopProcessing="true"> <match url="^your-original-path(.*)" /> <action type="Redirect" url="your-new-path{R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>

    Replace "your-original-path" with the current URL path you want to change, and "your-new-path" with the desired new URL path.

    Note that changing the URL path in IIS using a rewrite rule does not change the routing within your ASP.NET MVC application. It only redirects incoming requests to the new URL path.

Remember to restart your application or recycle the application pool in IIS for the changes to take effect.

Choose the approach that suits your needs and make the necessary modifications to change the root path or URL path in your ASP.NET MVC application or IIS configuration.

Have questions or queries?
Get in Touch