locked
setting the default page RRS feed

  • Question

  • User-309523270 posted

    Hi,

    I have an mvc application which do not go to the default page and goes to "page cannot be displayed" screen.

    I already set the default in the following locations:

    Startup.cs
    ======================

            public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    app.UseExceptionHandler("/Home/Error");
                    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                    //app.UseHsts();  //commented 2019.10.28 for deployment purposes
                }

                //Route.MapMvcAttributeRoutes();
                //app.UseHttpsRedirection();  //commented 2019.10.28 for deployment purposes
                app.UseStaticFiles(new StaticFileOptions()
                {
                    OnPrepareResponse = context =>
                    {
                        context.Context.Response.Headers.Add("Cache-Control", "no-cache, no-store");
                        context.Context.Response.Headers.Add("Expires", "-1");
                    }
                });

                app.UseCookiePolicy();
                app.UseAuthentication();
                app.UseSession();

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

                });
            }

    Application object -> Startup object -> Program

    I appreciate your input!

    Thanks,

    tinac99

    Friday, November 1, 2019 11:33 PM

All replies

  • User1289604957 posted

    Hi,

    I could see a similar thread here https://forums.asp.net/t/2152769.aspx?How+to+configure+in+startup+cs+Default+MapRoute+login+page

    Best regards,

    Maher

    Sunday, November 3, 2019 11:33 AM
  • User-1780421697 posted

    Are you debugging the application in visual studio and it is not going to Account->Login, if then what is response from browser 500 error or 404 or what? 

    You need to try it by CLI using dotnet run and it will show you actual issue with application., if there is any issue you will see there, another tip is create a logs folder in root of application and from web.config (after publish) enable logging and see the result sometime i have seen if you have any dependencies error or any other sort of programming issue with initial controller then this happened.

    try to comment the custom added code from startup files and then try it. you can also try to create another controller like home with simple index action and use 

     routes.MapRoute(
                                    name: "default",
                                    template: "{controller=Home}/{action=index}");

    Monday, November 4, 2019 1:59 AM
  • User711641945 posted

    Hi tinac99,

    I could get into the default page successfully by using your code.Could you share more details that could reproduce your issue?

    The reason for page cannot be displayed you could refer to:

    http://karunsubramanian.com/jboss/8-reasons-for-the-infamous-page-cannot-be-displayed-error/

    Best Regards,

    Rena

    Monday, November 4, 2019 2:00 AM
  • User-309523270 posted

    It's a 404 error....

    Monday, November 4, 2019 7:01 PM
  • User475983607 posted

    It's a 404 error....

    Perhaps you forgot an Area and the URL is /Identity/Account/login?  Keep in mind that adding [Authorize] to the Home controller will cause a redirect to the Login page if you are using the default Identity configuration.

    Monday, November 4, 2019 7:19 PM
  • User711641945 posted

    Hi tinac99,

    404 means the page not found,be sure your url is right.And your Controller and Action should be like below,no need to add  `Route` attribute:

    public class AccountController : Controller
    {         
        public IActionResult Login()
        {
            //your logic..
            return View();
        }
    }

    Best Regards,

    Rena

    Tuesday, November 5, 2019 1:20 AM