Share via

Authentication

Jagjit Saini 106 Reputation points
2021-07-16T05:02:27.223+00:00

Hi

How the below code works

<authentication mode="Forms">
<forms loginUrl="~/Home/Login" timeout="30" />
</authentication>

Main Layout File
<!DOCTYPE html>
@{
if (!User.Identity.IsAuthenticated)
{
Context.Response.Redirect(Url.Action("Login", "Home"));
}
}

Thanks

Developer technologies | ASP.NET Core | Other
0 comments No comments

Answer accepted by question author

Yijing Sun-MSFT 7,106 Reputation points
2021-07-16T08:24:23.3+00:00

Hi @Jagjit Saini ,
What's your problem? I don't understand your requirement clearly. These two ways are all works for Authentication. So,I suggest you could use the first method.
Note: You need to add "[Authorize]" in your HomeController.

Best regards,
Yijing Sun


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.