Why does MVC website on host logs off permanently after login?
-
19-10-2022 - |
Question
I uploaded my MVC website on hosting. But when I logon to the site, it permanently logs off. This doesn't occur locally. I have no clue about the cause of this problem.
Web.config:
<authentication mode="Forms">
<forms loginUrl="~/Login" timeout="60" slidingExpiration="true"/>
</authentication>
<roleManager defaultProvider="CustomRoleProvider" enabled="true">
<providers>
<clear/>
<add name="CustomRoleProvider" type="SmsMenu.Services.CustomRoleProvider"/>
</providers>
</roleManager>
Edit:
This the code to login:
LoginController:
public class LoginController : Controller
{
private SmsDBEntities db = new SmsDBEntities();
[HttpGet]
public ActionResult Index()
{
if (HttpContext.User.IsInRole("admin") )
{
return RedirectToAction("Insurance", "Insurance", new { area = "AdminsArea" });
}
return View();
}
[HttpPost]
public ActionResult Index(LoginViewModel userModel)
{
if (ModelState.IsValid)
{
CustomRoleProvider customRole = new CustomRoleProvider();
var id = customRole.ValidateUser(userModel);
if (id != null)
{
Session["UserId"] = id;
Session["Username"] = userModel.UserName;
string[] roles = customRole.GetRolesForUser(userModel.UserName.ToString());
customRole.CreateCookie(userModel);
foreach (var item in roles)
{
if (item == "admin")
{
return RedirectToAction("Insurance", "Insurance", new { Area = "adminsarea" });
}
}
}
}
return View();
}
Functions:
public void CreateCookie(LoginViewModel member)
{
FormsAuthentication.SetAuthCookie(member.UserName, member.RememberMe);
//save login log in db
}
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow