2
votes

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.

2
do you have a LoginController ?Gurgen Sargsyan
Yes. public class LoginController : ControlleriDipa

2 Answers

5
votes

Try to use

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

;

1
votes

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.