1

I've been having trouble with changing the default route of my ASP.Net Core web app. I had changed the default route to other page but it still redirects me to the previous page. Below is the snippet of my code for reference:

Startup.cs

public void Configure(IApplicationBuilder app, IWebHostEnvironment 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();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSession();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Main}"); //I had changed this but still redirect me Login
            });
        }

HomeController.cs

public class HomeController : Controller
    {
        public IActionResult Login()
        {
            return View();
        }

        [SessionTimeout]
        public IActionResult Main()
        {
            return View();
        }
    }

As you can see, there are 2 actions in my controller. Previously I used Login as the default route. Now I want the default route to be Main. But it still redirects me to Login. I also had tried to change the launchUrl, but still doesn't solve this issue.

Really appreciates any help. Thanks in advance.

1 Answer 1

3

It may be because of SessionTimeoutAttribute which you have used. Pls try commenting it and if you gets your issue solved then check in SessionTimeoutAttribute if you have redirected your action to Login then change it to Main.

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

1 Comment

Oh my god. It is! How come I didn't notice it earlier haha. Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.