Hi
In Web.config i gave below code . I want if user has not login , he should not be able to open any web form directly. User should be redirected to Login
Thanks
Hi
In Web.config i gave below code . I want if user has not login , he should not be able to open any web form directly. User should be redirected to Login
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Adarsh NigamRank #950 · 2.1K reputationPosted Aug 17, 2024, 9:36 AM EDT
You can achieve this by using the
andelements in your Web.config file. Here's an example:Here's how it works:
element denies access to all anonymous users (i.e., users who have not logged in). The?is a wildcard character that matches all anonymous users.element specifies that the following authorization settings only apply to the Login.aspx page.element allows all users (including anonymous users) to access the Login.aspx page. This is necessary because we want to allow users to access the login page even if they haven't logged in yet.With this configuration, when an anonymous user tries to access any page other than Login.aspx, they will be redirected to the Login.aspx page. Once they log in, they will be able to access the other pages.
Note that you'll also need to configure the authentication mode in your Web.config file. For example:
This sets the authentication mode to Forms authentication and specifies that the login page is Login.aspx.