Good Day,

I would like to ask regarding on Redirect or need to login first?

I have a Link on Homepage that if the user click that it will check if the user is logon or not if not then it will redirect on Login page?

Your Response is Highly Appreciated.


Recommended Answers

All 6 Replies

Good Day,

Forget to say im using and Active Directory Authentication

Thank you for your Response

I have already this Mr. Vishal, i have already an authentication login/logout parameters but the problem is on the linking authentications. if the user click the link and not yet logon, it will redirect on logon page so he can proceed further.


Have You seen this article I have mentioned above..

In that article they are throwing some error if the user is not authenticated..

    public bool IsAuthenticated(string domain, string username, string pwd)
      string domainAndUsername = domain + @"\" + username;
      DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);

        //Bind to the native AdsObject to force authentication.
        object obj = entry.NativeObject;

        DirectorySearcher search = new DirectorySearcher(entry);

        search.Filter = "(SAMAccountName=" + username + ")";
        SearchResult result = search.FindOne();

        if(null == result)
          return false;

        //Update the new path to the user in the directory.
        _path = result.Path;
        _filterAttribute = (string)result.Properties["cn"][0];
      catch (Exception ex)
        throw new Exception("Error authenticating user. " + ex.Message);

      return true;

In place of throw new Exception("Error authenticating user. " + ex.Message); You can use Response.Redirect("Login.aspx",false); so that it will redirect the user to the login page if the users are not authenticated .. Use this code in Linkbutton click event..

Only time you should redirect to a login page is if the user clicks a link to go there, or they've bookmarked a page that requires them to be authenticated. If they're just viewing public pages, then there is no reason to have a user login.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.