2

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 ? Commented Jan 20, 2016 at 7:08
  • Yes. public class LoginController : Controller Commented Jan 20, 2016 at 7:10

2 Answers 2

5

Try to use

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

;

Sign up to request clarification or add additional context in comments.

1 Comment

I have tried it. But url attribute is not supported in ASP .NET 5 MVC 6
1

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.

2 Comments

launch URL and default route are different things
@NikaGamkrelidze I thought that's what he was asking

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.