iDipa
iDipa

Reputation: 345

Default routing change ASP .Net 5 MVC 6

I have created a project ASP .NET 5 MVC 6. In that I want to change default routing. So in StartUp.cs file I have changed the controller and action name. But it is redirecting to old route instead new one. Below is code for old and new default routes.

Old default route

public void Configure(IApplicationBuilder app) {  
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
}

New (change is only of controller and action name) route

public void Configure(IApplicationBuilder app) {  
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Login", action = "Login" });
            });
}

Help to solve this issue. I want to redirect to my another controller-action method. Project is of ASP .NET 5 MVC 6 and login controller is of 'MVC controller class' type.

Thank You.

Upvotes: 2

Views: 5941

Answers (2)

jcmontx
jcmontx

Reputation: 439

In ASP.NET Core (former ASP.NET 5) you can set the default route in the "launchSettings.json" file. You will find it in your project's Properties.

Upvotes: 1

Gurgen Sargsyan
Gurgen Sargsyan

Reputation: 1087

Try to use

app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Login}/{action=Login}/{id?}");
            })

;

Upvotes: 5

Related Questions