Not 100% sure about the exact problem. If you have no database at all and want to store hardcoded credentials you could have a look at http://geekswithblogs.net/AaronLi/archive/2007/02/20/106761.aspx (Forms
authentication, not the last part where credentials are stored directly in the web.config file).
You are uisng ASP.NET 4.x or ASP.NET Core? If ASP.NET Core you could use ASP.NET Identity.
All this may seem a bit more complex than "rolling" your own but the benefit iis that you can start with something simple (my understanding is that for now you don't even have a database where you could store credentials) but you'll be able to move the
app forward (as the app itselfy doesn't have to care where credentials are stored).
I made a simple example that only simulates redirecting to the home page after login.
Since there is no database, the login name and password are fixed in my example. However I still suggest that you use a database to log in, which will be more safer and more dynamic.
More details, you could refer to below code:
HomeController:
public class HomeController : Controller
{
//This is welcome page
public ActionResult Index()
{
return View();
}
public ActionResult Login()//Here you need to add the passed parameters
{
return View();
}
[HttpPost]
public ActionResult Login(String UserName,String Password)//Here you need to add the parameters
{
if (UserName=="11"&&Password=="11")//It is assumed here that the username and password are verified
{
return RedirectToAction("Index");
}
return View();
}
}
}
Member
134 Points
507 Posts
Mvc redirect login view to another view from login
Apr 23, 2020 06:56 PM|emaak|LINK
Hi ,im new to MVc.
tryying o simple login page dont have database with manual usernam and password wants to redirect page to welcom e page..Any suggestions
All-Star
48530 Points
18075 Posts
Re: Mvc redirect login view to another view from login
Apr 23, 2020 09:07 PM|PatriceSc|LINK
Hi,
Not 100% sure about the exact problem. If you have no database at all and want to store hardcoded credentials you could have a look at http://geekswithblogs.net/AaronLi/archive/2007/02/20/106761.aspx (Forms authentication, not the last part where credentials are stored directly in the web.config file).
You are uisng ASP.NET 4.x or ASP.NET Core? If ASP.NET Core you could use ASP.NET Identity.
All this may seem a bit more complex than "rolling" your own but the benefit iis that you can start with something simple (my understanding is that for now you don't even have a database where you could store credentials) but you'll be able to move the app forward (as the app itselfy doesn't have to care where credentials are stored).
Contributor
3710 Points
1043 Posts
Re: Mvc redirect login view to another view from login
Apr 24, 2020 05:45 AM|Yongqing Yu|LINK
Hi, emaak
I made a simple example that only simulates redirecting to the home page after login.
Since there is no database, the login name and password are fixed in my example. However I still suggest that you use a database to log in, which will be more safer and more dynamic.
More details, you could refer to below code:
HomeController:
Login.cshtml
Index.cshtml
Here is the result.
Best Regards,
YongQing.
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
134 Points
507 Posts
Re: Mvc redirect login view to another view from login
Apr 24, 2020 06:08 PM|emaak|LINK
Hi Yongqing,
Thank you.Got it. its working now
Member
134 Points
507 Posts
Re: Mvc redirect login view to another view from login
Apr 24, 2020 07:11 PM|emaak|LINK
Thank you for the information.