Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to change the default home/landing to my own controller /Home/Index ? #6235

Closed
orchardc opened this issue May 21, 2020 · 8 comments

Comments

@orchardc
Copy link

As I'd like to redirect the homepage to use my own controller /Home/Index

@Piedone
Copy link
Member

Piedone commented May 21, 2020

You don't need to redirect anything. If you specify your controller action's route as the home route (I think just "/" should work), like with attribute routing then that's what will come up when you open the homepage.

@orchardc
Copy link
Author

Hi, this doesn't work:
routes.MapAreaControllerRoute(
name: "Home",
areaName: "MyCode",
pattern: "/",
defaults: new { controller = "MyController", action = "Index" }
);

@Piedone
Copy link
Member

Piedone commented May 21, 2020

How exactly is it not working?

@orchardc
Copy link
Author

It ignore this route, still directly go to the landing page.

@Piedone
Copy link
Member

Piedone commented May 22, 2020

Let's try to make this work in a simplest way: Please create a controller in your module where the action just returns a string or something, and use attribute routing to hook it to the homepage. Enable the module, then try it out. If it doesn't work then open the action directly with the default route. Let us know if this works and post your code.

@Skrypt
Copy link
Contributor

Skrypt commented Jun 3, 2020

You can change the homepage route by changing it in the database.

You will do this SQL Query to find the proper record in the DB :

SELECT * FROM Document WHERE Type = 'OrchardCore.Settings.SiteSettings, OrchardCore.Settings'

And then change this part of the JSON data with what you need :

{
  "HomeRoute": {
    "area": "OrchardCore.Contents",
    "controller": "Item",
    "action": "Display",
    "contentItemId": "12121212121212"
  }
}

Let's add this to the documentation please as this question is often asked. @agriffard

@agriffard
Copy link
Member

@Skrypt I tried to create a Tools module with an admin page to set the HomeRoute.

The homeRoute is correctly updated but, it still needs to update the current one to SetHomepage = false and if there is a contentItemId, update the content that has the new contentItemId with SetHomepage = true.

If you want to take a look:
https://github.com/agriffard/Tools.OrchardCore/blob/41918a67495dc4866b74a5c49720407412cee00c/src/Tools/Services/ToolsService.cs#L31

@jtkech
Copy link
Member

jtkech commented Jun 23, 2020

@orchardc

You just need to disable the HomeRoute feature, no feature really depends on it, Autoroute just provides a way to define the home route settings that are then used by the HomeRoute feature

So if you disable the HomeRoute feature you can then define an home page in a regular mvc way, as @Piedone suggested, with a route attribute [Route("")] or by using a MapAreaControllerRoute()

public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, ...)
{
    routes.MapAreaControllerRoute(
        name: "Html.Demo.Test",
        areaName: "OrchardCore.Html", <= needs to be the module assembly name
        pattern: "",
        defaults: new { controller = "Demo", action = "Test" }
    );
}

@OrchardCMS OrchardCMS locked and limited conversation to collaborators Apr 25, 2024
@Piedone Piedone converted this issue into discussion #15862 Apr 25, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants