0
votes

I'vew got an company internal website containing different areas implemented with asp.net core's area-logic.

I'd like to redirect the users to a homepage of their choice.

For Example:
User A: contonso.com/ showing index of area invoices
User B: contonso.com/ showing index of area customers

Possible workaround: Use a generic home controller that redirects the user to the appropriate area but i would like to know if there is a more generic solution using the build-in routing capabilities.

At the moment, i would stores those information in a database but actually i don't care how to configure, as long as I'm able to do the routing dynamically.

The docs and google doesn't say anything about this case.

Is there any way to get arround a custom middleware? Some buildin support, or an existing nuget-package?

2

2 Answers

0
votes

You could try Middleware to redirect the requests based on your logic.

Here is a demo code for MVC Controller:

                   app.Use(async (context, next) =>
        {
            if (context.Request.Path == "/" && context.User.Identity.Name == "[email protected]")
            {
                context.Response.Redirect("Home/About", true);
            }
            else if (context.Request.Path == "/" && context.User.Identity.Name == "[email protected]")
            {
                context.Response.Redirect("Home/Contact", true);
            }
            await next();
        });

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

Note, change the redirect URL and MVC Route based on your Area

-1
votes

U can use action like this:

public IActionResult MyIndex()
{
    string action = // get action for user
    return RedirectToAction(action, "Home")
}

along with tag helper:

<a asp-controller="Home" asp-action="MyIndex">Go somewhere</a>