Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6198135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:56:39+00:00 2026-05-24T03:56:39+00:00

Basically I keep getting thrown out from my asp.net mvc application because the User.Identity.IsAuthenticated

  • 0

Basically I keep getting thrown out from my asp.net mvc application because the User.Identity.IsAuthenticated is false, this only happens because of the code below related to task comments (marked ** below) – I cannot figure out why it is happening, any help is appreciated.

Code below inside a custom attribute on my base controller that authenticates users, if not authenticated I throw an exception like so:

if (!httpContext.User.Identity.IsAuthenticated)
   throw new NoAccessException("unauthorized user"); // invalid users are thrown out...

Code that is causing the User.Identity.IsAuthenticated + User.Identity.Name to become null is:

[HttpGet]
    public ActionResult TaskDetail(int houseid, int taskid)
    {

        //NOTE: _repo is a simple ISession over Linq to Sql
        //GetCurrentUser() is a extention method which gets the current logged on user
        //i.e. User.Identity.Name so I can get the users credentials

        var loggedonuser = _repo.GetCurrentUser();

        var _house= _repo.Single<House>(x => x.HouseID== houseid&& x.ClientID== loggedonuser.CompanyID);

        if (_house== null)
            throw new NoAccessException();

        var summary = _instruction.ToSummaryDTO();

        var companies = _repo.All<Company>();
        //var users = _repo.All<User>();

        var task = _repo.Single<Task>
            (x => x.HouseID== _house.HouseID && x.CompanyID == loggedonuser.CompanyID);

        var dto = new TaskDTO
        {
            TaskID = task.TaskID,
            Title = task.Title,
            Description = task.Description,
            DateCreated = task.DateCreated,
            IsClosed = task.IsClosed,
            CompanyID = companies.Where(y => task.CompanyID == y.CompanyID).SingleOrDefault().Identifier
        };

        **dto.AllComments** = _repo.All<TaskComment>()
            .Where(x => x.TaskID == task.TaskID)
            .OrderByDescending(x => x.Timestamp)
            .Select(x => new TaskCommentDTO
            {
                Comment = x.Comment,
                Timestamp = x.Timestamp,
                CompanyID = companies.Where(y => x.CompanyID == y.CompanyID).SingleOrDefault().Identifier
            });


        return View(new TaskViewModel
        {
            Summary = summary,
            TaskDetail = dto,
        });
    }

NOTE: If I omit the dto.AllComments (IQueryable) then everything works fine, I never get thrown out my system or more importantly User.Identitiy remains correct…. I have tried to convert to list – which is what I ideally want however that does not work either, maybe there is something wrong with my linq method…

My DTO:

public class TaskDTO
{
    public int TaskID { get; set; }
    public bool IsClosed { get; set; }
    public string CompanyID { get; set; }
    public string AssignedTo { get; set; }
    public DateTime DateCreated { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public IQueryable<TaskCommentDTO> AllComments { get; set; }
}


public class TaskCommentDTO
{
    public string CompanyID { get; set; }
    public string UserID { get; set; }
    public DateTime Timestamp { get; set; }
    public string Comment { get; set; }
}

EDIT: where exception is being thrown

I have traced the exception now, I overrided the code below in my base controller which helped me discover the bug:

    protected override void Execute(System.Web.Routing.RequestContext requestContext)
    {
        base.Execute(requestContext);
    }

After the page finished loading, this code was ran once again, when I checked out the request context In the Values for RouteData I found “Error” and “FileNotFound”, at this point the user gets nulled out too, now I need to find out which file is not found… 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:56:40+00:00Added an answer on May 24, 2026 at 3:56 am

    From your code:

    var task = _repo.Single<Task>
                (x => x.HouseID == _house.HouseID && x.CompanyID == loggedonuser.CompanyID);
    
        var dto = new TaskDTO
        {
            TaskID = task.TaskID,
            Title = task.Title,
            Description = task.Description,
            DateCreated = task.DateCreated,
            IsClosed = task.IsClosed,
            CompanyID = companies.Where(y => task.CompanyID == y.CompanyID).SingleOrDefault().Identifier
        };
    

    This line:

    CompanyID = companies.Where(y => task.CompanyID == y.CompanyID).SingleOrDefault().Identifier
    

    calls the property Identifier on a SingleOrDefault() result which could be null. Have you checked that this is ok. Is it on this line that the exception is thrown?

    Note you can use IEnumerable instead of IQueryable; probably won’t make any difference but if that’s the crashing part you can try it for nothing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I am trying to restart a service from a php web page. Here
Basically, I'm trying to tap into the Soap pipeline in .NET 2.0 - I
Basically I’ve heard that certain conditions will cause .NET to blow past the finally
I keep on getting this error when running one of my scripts; PHP Fatal
Basically what I want to do it this: a pdb file contains a location
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
Basically I have some code to check a specific directory to see if an
Basically I'm going to go a bit broad here and ask a few questions
Basically, I would like a brief explanation of how I can access a SQL
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.