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.

EOS

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.

EOS

Have You seen this article I have mentioned above..
http://msdn.microsoft.com/en-us/library/ms180890%28v=vs.80%29.aspx

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);

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

        DirectorySearcher search = new DirectorySearcher(entry);

        search.Filter = "(SAMAccountName=" + username + ")";
        search.PropertiesToLoad.Add("cn");
        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, networking, learning, and sharing knowledge.