Forms Authentication App - Need User Identity from the start Help!

Posted on 2012-09-14
Last Modified: 2012-09-25
Hello all,

I have an app that uses forms auth that was working fine on my localhost but of course when I place it out on IIS no dice.   I have a home page the user hits in the site under the root where the web.config lives as well of course that uses forms auth.  In the home page I need to check if the user is a certain type then redirect based on if they are.  I was trying to use:


But that does not work of course it's empty.  So how can I do this either off a global.asax session start or whatever I need to do.  I am really hoping I don't have to pull out the redirect pages and code from this main app as I want it to live there.  I somehow need the user identity.
Question by:sbornstein2
    LVL 26

    Accepted Solution

    If you are using <authentication mode="Forms"> in your web.config and your connectionstring is defined in your web.config and your connectionstring is valid (the db exists on the server) then, you should be able to get the UserName from the membership provider in a few different ways.

    Dim username As String = My.User.Name
    Dim username As String = HttpContext.Current.User.Identity.Name
    Dim username As String = Page.User.Identity.Name
    ' The second one is probably the most robust.

    Open in new window

    Regarding the "user being a certain type", I suspect membership roles would be the go:
    Examining ASP.NET's Membership, Roles, and Profile - Part 1

    LVL 23

    Expert Comment

    by:Roopesh Reddy

    Context.User.Identity.Name should solve your problem!

    Check the MSDN article -

    Hope it helps u...

    Author Closing Comment


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now