System.ComponentModel.Win32Exception:等待操作超时Roles.Provider.GetRolesForUser MVC C#

时间:2015-12-04 17:20:09

标签: c# model-view-controller roles win32exception

有时我会收到此错误,但我不知道原因:?:

enter image description here

当用户登录时我添加了角色:

  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);

并且我认为这样做:

@{
    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>
        }
}

所以我不知道为什么我会得到这个例外,但是我想当我离开网站并且经过一段时间再刷新页面后我会得到它,但是当我进入页面时有时会抛出异常 ,我不记得确切的。

用户登录后,我添加角色,直到用户注销所有角色都不被销毁

也许有人知道如何修复它?

0 个答案:

没有答案
相关问题