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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Adarsh NigamPosted Aug 17, 2024, 1:36 PM
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.