Base solution for your next web application
Open Closed

Changing initial page which shows when first launching project - currently goes to login page, but I want a welcome page showing site info BEFORE having to login #12181


User avatar
0
wingers created

Hi

New to ASP.NET Zero so apologies if a basic / stupid question.

Currently when I run project it goes to the login page (if use not already logged in), I instead want it to go to a "welcome" page which shows information about my site and where I would then have a login button for users to login and go to the main site using the Zero layout etc.

So main page wouldn't have sidebar or anything it would just have custom Bootstrap CSS to show logo, site information and a login button etc.

I know there is a .Web.Public project, but a) this is outdated and b) I was hoping to do it in a simpler way than having a separate public project just for one initial page.

Hope this make senes, if not please ask what needs to be clarified.

Thank you all


13 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi wingers

    *.Web.Public project has been updated with this issue. This change will be reflected in v14.0. By applying the changes here, you will be greeted with a more updated interface. Or, if your project is MVC, you can create a page and change the opening page orientation in HomeController. If Angular, you can change the start page in app-routing.module.ts. Changes here will redirect you to this page for the first time.

  • User Avatar
    0
    wingers created

    Thanks for reply.

    My project is MVC.

    I created a new controller (.Web.Mvc\Areas\App\Controllers\StartupController.cs) and a new page (.Web.Mvc\Areas\App\Views\Startup\Index.cshtml), but can't see to work out how to change the HomeController to load that new page first correctly as currently HomeController has [AbpMvcAuthorize] and code to check various criteria as to what page to load, even removing the [AbpMvcAuthorize] and setting it to just my page didn't work for me as initially got error. Comments please?

  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi wingers

    Here, you will need to make changes not to the controller in the Area section, but to the HomeController in the controller in the main. As stated below

    public class HomeController : MvcDemoProjectControllerBase
    {
        //
        
        public async Task<IActionResult> Index(string redirect = "", bool forceNewRegistration = false)
        {
            if (forceNewRegistration)
            {
                await _signInManager.SignOutAsync();
            }
    
            if (redirect == "TenantRegistration")
            {
                return RedirectToAction("SelectEdition", "TenantRegistration");
            }
    
            return AbpSession.UserId.HasValue ?
                RedirectToAction("Index", "Home", new { area = "AppAreaName" }) :
                RedirectToAction("WelcomePage", "Home"); // You can specify it on the application opening page
        }
    
        public IActionResult WelcomePage()
        {
            return View();
        }
    

  • User Avatar
    0
    wingers created

    Thank you for your response.

    So I have added my new page and its controller as documented in previous reply - called Startup.

    I have now edited the correct HomeController.cs as below, but when running I get error as below about not being logged on, but the whole point is I don't want to have to be logged on to see this first page

    using System.Threading.Tasks;
    using Abp.Runtime.Session;
    using Microsoft.AspNetCore.Identity;
    using Microsoft.AspNetCore.Mvc;
    using PCADemo.Identity;
    using PCADemo.Web.Controllers;
    
    namespace PCADemo.Web.Controllers
    {
        public class HomeController : PCADemoControllerBase
        {
            private readonly SignInManager _signInManager;
    
            public HomeController(SignInManager signInManager)
            {
                _signInManager = signInManager;
            }
    
            public async Task<IActionResult> Index(string redirect = "", bool forceNewRegistration = false)
            {
                if (forceNewRegistration)
                {
                    await _signInManager.SignOutAsync();
                }
    
                if (redirect == "TenantRegistration")
                {
                    return RedirectToAction("SelectEdition", "TenantRegistration");
                }
    
                return AbpSession.UserId.HasValue ?
                    RedirectToAction("Index", "Home", new { area = "App" }) :
                    RedirectToAction("Index", "Startup", new { area = "App" }); // You can specify it on the application opening page
            }
    
            public IActionResult WelcomePage()
            {
                return View();
            }
    
    
        }
    }
    
    
    
    

  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi wingers

    The problem here is that you use _Layout.cshtml found in the App. You can create a separate layout for the start page.

  • User Avatar
    0
    wingers created

    Okay thanks, rearrange my code and now have it working.

    One final question - when logging out how can I have it redirect back to my startup page rather than going back to /Account/Login

  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi wingers

    You can change the RedirectToAction value of the Logout method in the AccountController in main.

  • User Avatar
    0
    wingers created

    Perfect, thank you very much

  • User Avatar
    0
    oguzhanagir created
    Support Team

    We're glad we could help, good work.

  • User Avatar
    0
    wingers created

    one final question relating to the login page. How do I change the background image?

    I assume I could replace login.png and login-dark.png in *.Web.Mvc\wwwroot\metronic\assets\media\svg\illustrations

    But also assumed I could edit path in *.Web.Mvc\Views\TenantRegistration_Layout.cshtml, but this method doesn't work?

  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi wingers

    You can change the background images by changing the paths specified in the screenshot below. The changes will be visible after performing a hard refresh in the browser.

    TenantRegistration/_Layout.cshtml

    Account/_Layout.cshtml

  • User Avatar
    0
    wingers created

    perfect thanks

  • User Avatar
    0
    oguzhanagir created
    Support Team

    You're welcome, good work.