0

Sometimes I get this error and I don't know why :?:

enter image description here

When user log on I adding roles:

  if (!System.Web.Security.Roles.RoleExists(user.roles.Title))                        
 System.Web.Security.Roles.CreateRole(user.roles.Title);
          if (!System.Web.Security.Roles.IsUserInRole(Convert.ToString(user.Id), user.roles.Title))
                                        System.Web.Security.Roles.AddUserToRole(Convert.ToString(user.Id), user.roles.Title);

And in view I'm doing this:

@{
    bool isLoggedIn = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
}

@if (isLoggedIn)
{
 //Some view logic


              @if (Roles.Provider.GetRolesForUser(User.Identity.Name).Contains("Admin") || Roles.Provider.GetRolesForUser(User.Identity.Name).Contains("Creator"))//Here I get exception, but why?
        {
            <li class="right icon">
                <div class="drop">
                    <a href="@Url.Action("Admin", "Logged")" class="tooltip">
                        <img src="@Url.Content("~/Images/Admin.png")" alt="Admin" height="18" width="18" id="Admin"/>
                        <span>Admin</span>
                    </a>
                </div>
            </li>
        }
}

So I don't know why I get this exception, but I think I get it when I leave website and after some time again refreshing page, but maybe sometimes throw exception when I going within pages ,I do not remember exactly about this.

After user log on i adding roles and until user log out all roles dont be destroyed

Maybe someone knows how to fix it?

  • Is there a timeout value you can "monkey with" (increment)? – B. Clay Shannon-B. Crow Raven Dec 04 '15 at 17:24
  • Maybe I think this timeout value can do it: ? I think when i set it to 1000 it redirecting me to page and when trows exception maybe becouse roles was deleted by this redirected timeout? Or i'm dont know:? – user3398571 Dec 04 '15 at 17:29
  • Forget to mention,but this my view is _layout :) – user3398571 Dec 04 '15 at 17:31
  • 1
    Just run the same sql query on the database by yourself to check that query is fast enough. If query is fast, then you can configure your database timeout. Or, it's good to check that database is really available in time when you perform a query, maybe you can't reach DB at all. – cassandrad Dec 04 '15 at 17:32
  • It reach DB becouse i using DB in controller, in view it just data Review. And I get exception on roles line so considering to that it cannot be with sql, although exception is sql unless roles using sql, but i dont think so :? And my query is fast, becouse i dont doing some space things, I'M just geting user if exist i adding roles and taking 10 records from Database. And thats all – user3398571 Dec 04 '15 at 17:44

0 Answers0