You must Sign In to post a response.
  • Category: ASP.NET

    Read cookies values in asp.net c# (Windows authentication)

    Hello.
    I have one page where I want to read cookies on page load to get user name and password.
    I have "Windows" authentication in my web.config which I can't change.

    How can I achieve that.
  • #768799
    Hai Pranjal,
    If the windows authentication is enabled for the Web Application, it means your application will use the windows credentials to log-in to the application.
    In this case, you need to use IPrincipal class interface to get the user details, group details etc.
    Below code can be used to get the windows credentials and then you can keep them in cookies:

    using System.Security.Principal;

    var user = System.Web.HttpContext.Current.User;
    var userName = user.Identity.Name;

    Now you can place the user name in to cookie value.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com


  • Sign In to post your comments