I want to make a login page that opens when I start up the ASP.NET MVC web application. I also want to automatically redirected the user to the Home/Index page after a successful login.
Furthermore the login page has a Register button which is redirected to the register page, I want the register page to be redirected to the Home/Index after successful registration.
Right-click your Project within the Solution Explorer. Choose Properties. Select the Web tab on the left-hand side. Under the Start Action section, define the Specific Page you would like to default to when the application is launched.
u can do this simply by right clicking on ur singin. aspx page and set it as ur start page. The default sign-in page is done in the config file authentication/authorisation sections.
You do not want to make Login as home page. It is not a good design. Mainly because after a user login and enters https://yoursite.com
in browser, you do not want to display Login page again.
Instead, you just need to apply [Authorize] to home controller.
[Authorize]
public class HomeController : BaseController
{
// ...
}
Or Global Filter
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new AuthorizeAttribute());
}
}
If a user access your home page, s/he will be redirected to Login Page first with ReturnUrl in QueryString.
For example, https://yoursite/Account/Login?ReturnUrl=%2f
Make sure you set your login page in loginUrl in web.config.
<system.web>
...
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880"/>
</authentication>
</system.web>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With