i'm new with ASP.net web razor page app and i'm currently creating login validation form by taking data from specific database. I'm using FormsAuthentication model to bound directory during log in process. But instead i received red-line on the model.
Please help me to solve my issue
login.cshtml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using RedoAssignment.Models;
using Microsoft.EntityFrameworkCore;
using RedoAssignment.Table;
using System.Web;
namespace RedoAssignment.Pages{publicclass loginModel :PageModel{publicActionResultIndex(){returnPage();}[HttpGet]publicActionResult login(){returnPage();}[HttpPost]publicActionResult login(Models.RedoAssignmentContext context){if(ModelState.IsValid){FormsAuthentication.SetAuthCookie(User.email,User.password); //Error statementreturnRedirectToAction("Index","Home");}else{ModelState.AddModelError("","Login data is incorrect!");}returnPage();}}
Hi, thank you for your response. I have changed the method by using cookie authentication and it shows no error. However i found another problem where the object from
User database does not get called during login process. Instead it returns to index page, it only stays at the same page after pressing the submit button.
Hi, thank you for your response. I have changed the method by using cookie authentication and it shows no error. However i found another problem where the object from
User database does not get called during login process. Instead it returns to index page, it only stays at the same page after pressing the submit button.
If you want a code review and assistance to find the bug then share all relevant source code. Otherwise, there's not much the community can do for you.
Instead it returns to index page, it only stays at the same page after pressing the submit button.
Please debug your project. From your description and codes, it seems that the ModelSate is invaild, so it didn't redirect to index page but stay at the current page.
Best Regards,
Jiadong Meng
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
4 Points
21 Posts
FormsAuthentication and IsValid method does not exist in current context error
Apr 21, 2020 08:20 AM|emirryhn|LINK
i'm new with ASP.net web razor page app and i'm currently creating login validation form by taking data from specific database. I'm using FormsAuthentication model to bound directory during log in process. But instead i received red-line on the model. Please help me to solve my issue
login.cshtml.cs
User.cs model
</div> </div> </div>
All-Star
53041 Points
23611 Posts
Re: FormsAuthentication and IsValid method does not exist in current context error
Apr 21, 2020 12:21 PM|mgebhard|LINK
As far as I know, Forms Authentication does not exist in Razor Pages. Use Cookie Authentication.
https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-3.1
Member
4 Points
21 Posts
Re: FormsAuthentication and IsValid method does not exist in current context error
Apr 21, 2020 03:28 PM|emirryhn|LINK
Hi, thank you for your response. I have changed the method by using cookie authentication and it shows no error. However i found another problem where the object from User database does not get called during login process. Instead it returns to index page, it only stays at the same page after pressing the submit button.
All-Star
53041 Points
23611 Posts
Re: FormsAuthentication and IsValid method does not exist in current context error
Apr 21, 2020 03:57 PM|mgebhard|LINK
If you want a code review and assistance to find the bug then share all relevant source code. Otherwise, there's not much the community can do for you.
Participant
1320 Points
491 Posts
Re: FormsAuthentication and IsValid method does not exist in current context error
Apr 22, 2020 07:34 AM|jiadongm|LINK
Hi emirryhn,
Please debug your project. From your description and codes, it seems that the ModelSate is invaild, so it didn't redirect to index page but stay at the current page.
Best Regards,
Jiadong Meng