I need to get the current user name in MVC 5





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







3















I need to use HttpContext.Current.User.Identity.Name, but it always comes back as null. I have Anonymous Authentication set to disabled and Windows Authentication set to Enabled in the project properties. I also have the below lines in my web.config.



<authentication mode="Windows" />
<authorization>
<deny users="?"/>
</authorization>

<providers>
....
<add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>


Server settings



Every post I have looked at has suggested doing the steps I have already done, but I still have no luck.










share|improve this question

























  • Hosted in IIS or checking in VS?

    – mbharanidharan88
    Nov 16 '18 at 14:36













  • Possible duplicate of HttpContext.Current.User.Identity.Name is Empty

    – mbharanidharan88
    Nov 16 '18 at 14:37











  • Just checking in VS on localhost

    – sjohn285
    Nov 16 '18 at 14:38






  • 2





    Also make sure you aren't trying to access the HttpContext identity too early in the application pipeline, such as in the Application_Start method of the Global.asax, as the identity won't be available there.

    – Thomas
    Nov 16 '18 at 14:45











  • Thanks Thomas! You were correct, I was getting the null error as soon as I ran the application. I moved the code into where I needed to get the user and it's working correctly now. If you make an answer I will mark it.

    – sjohn285
    Nov 16 '18 at 14:51


















3















I need to use HttpContext.Current.User.Identity.Name, but it always comes back as null. I have Anonymous Authentication set to disabled and Windows Authentication set to Enabled in the project properties. I also have the below lines in my web.config.



<authentication mode="Windows" />
<authorization>
<deny users="?"/>
</authorization>

<providers>
....
<add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>


Server settings



Every post I have looked at has suggested doing the steps I have already done, but I still have no luck.










share|improve this question

























  • Hosted in IIS or checking in VS?

    – mbharanidharan88
    Nov 16 '18 at 14:36













  • Possible duplicate of HttpContext.Current.User.Identity.Name is Empty

    – mbharanidharan88
    Nov 16 '18 at 14:37











  • Just checking in VS on localhost

    – sjohn285
    Nov 16 '18 at 14:38






  • 2





    Also make sure you aren't trying to access the HttpContext identity too early in the application pipeline, such as in the Application_Start method of the Global.asax, as the identity won't be available there.

    – Thomas
    Nov 16 '18 at 14:45











  • Thanks Thomas! You were correct, I was getting the null error as soon as I ran the application. I moved the code into where I needed to get the user and it's working correctly now. If you make an answer I will mark it.

    – sjohn285
    Nov 16 '18 at 14:51














3












3








3








I need to use HttpContext.Current.User.Identity.Name, but it always comes back as null. I have Anonymous Authentication set to disabled and Windows Authentication set to Enabled in the project properties. I also have the below lines in my web.config.



<authentication mode="Windows" />
<authorization>
<deny users="?"/>
</authorization>

<providers>
....
<add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>


Server settings



Every post I have looked at has suggested doing the steps I have already done, but I still have no luck.










share|improve this question
















I need to use HttpContext.Current.User.Identity.Name, but it always comes back as null. I have Anonymous Authentication set to disabled and Windows Authentication set to Enabled in the project properties. I also have the below lines in my web.config.



<authentication mode="Windows" />
<authorization>
<deny users="?"/>
</authorization>

<providers>
....
<add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>


Server settings



Every post I have looked at has suggested doing the steps I have already done, but I still have no luck.







asp.net-mvc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 14:45







sjohn285

















asked Nov 16 '18 at 14:33









sjohn285sjohn285

12211




12211













  • Hosted in IIS or checking in VS?

    – mbharanidharan88
    Nov 16 '18 at 14:36













  • Possible duplicate of HttpContext.Current.User.Identity.Name is Empty

    – mbharanidharan88
    Nov 16 '18 at 14:37











  • Just checking in VS on localhost

    – sjohn285
    Nov 16 '18 at 14:38






  • 2





    Also make sure you aren't trying to access the HttpContext identity too early in the application pipeline, such as in the Application_Start method of the Global.asax, as the identity won't be available there.

    – Thomas
    Nov 16 '18 at 14:45











  • Thanks Thomas! You were correct, I was getting the null error as soon as I ran the application. I moved the code into where I needed to get the user and it's working correctly now. If you make an answer I will mark it.

    – sjohn285
    Nov 16 '18 at 14:51



















  • Hosted in IIS or checking in VS?

    – mbharanidharan88
    Nov 16 '18 at 14:36













  • Possible duplicate of HttpContext.Current.User.Identity.Name is Empty

    – mbharanidharan88
    Nov 16 '18 at 14:37











  • Just checking in VS on localhost

    – sjohn285
    Nov 16 '18 at 14:38






  • 2





    Also make sure you aren't trying to access the HttpContext identity too early in the application pipeline, such as in the Application_Start method of the Global.asax, as the identity won't be available there.

    – Thomas
    Nov 16 '18 at 14:45











  • Thanks Thomas! You were correct, I was getting the null error as soon as I ran the application. I moved the code into where I needed to get the user and it's working correctly now. If you make an answer I will mark it.

    – sjohn285
    Nov 16 '18 at 14:51

















Hosted in IIS or checking in VS?

– mbharanidharan88
Nov 16 '18 at 14:36







Hosted in IIS or checking in VS?

– mbharanidharan88
Nov 16 '18 at 14:36















Possible duplicate of HttpContext.Current.User.Identity.Name is Empty

– mbharanidharan88
Nov 16 '18 at 14:37





Possible duplicate of HttpContext.Current.User.Identity.Name is Empty

– mbharanidharan88
Nov 16 '18 at 14:37













Just checking in VS on localhost

– sjohn285
Nov 16 '18 at 14:38





Just checking in VS on localhost

– sjohn285
Nov 16 '18 at 14:38




2




2





Also make sure you aren't trying to access the HttpContext identity too early in the application pipeline, such as in the Application_Start method of the Global.asax, as the identity won't be available there.

– Thomas
Nov 16 '18 at 14:45





Also make sure you aren't trying to access the HttpContext identity too early in the application pipeline, such as in the Application_Start method of the Global.asax, as the identity won't be available there.

– Thomas
Nov 16 '18 at 14:45













Thanks Thomas! You were correct, I was getting the null error as soon as I ran the application. I moved the code into where I needed to get the user and it's working correctly now. If you make an answer I will mark it.

– sjohn285
Nov 16 '18 at 14:51





Thanks Thomas! You were correct, I was getting the null error as soon as I ran the application. I moved the code into where I needed to get the user and it's working correctly now. If you make an answer I will mark it.

– sjohn285
Nov 16 '18 at 14:51












1 Answer
1






active

oldest

votes


















0














Check it out with this



string userName = System.Web.HttpContext.Current.User.Identity.Name


or



User.Identity.Name





share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339857%2fi-need-to-get-the-current-user-name-in-mvc-5%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Check it out with this



    string userName = System.Web.HttpContext.Current.User.Identity.Name


    or



    User.Identity.Name





    share|improve this answer






























      0














      Check it out with this



      string userName = System.Web.HttpContext.Current.User.Identity.Name


      or



      User.Identity.Name





      share|improve this answer




























        0












        0








        0







        Check it out with this



        string userName = System.Web.HttpContext.Current.User.Identity.Name


        or



        User.Identity.Name





        share|improve this answer















        Check it out with this



        string userName = System.Web.HttpContext.Current.User.Identity.Name


        or



        User.Identity.Name






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 16 '18 at 16:32

























        answered Nov 16 '18 at 16:25









        rykamolrykamol

        310210




        310210
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339857%2fi-need-to-get-the-current-user-name-in-mvc-5%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            List item for chat from Array inside array React Native

            Thiostrepton

            Caerphilly