I've recently developed a C# ASP.NET MVC 4.5 application and I have some strange issues with it after deploying it. I developed the application on VS2015 and deploy it on IIS8(WINDOWS SERVER 2012) and on IIS7 (WINDOWS SERVER 2008 R2). I HAVE THIS PROBLEM ON THE SERVERS BUT NOT ON VS2015 WILL DEVELOPING THE APPLICATION.
So first this is the error returned by the server:image of the error
this is the code of the usercontroller.cs :
using MAGELLANAdminV2.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MAGELLANAdminV2.Controllers
{
public class UsersController : Controller
{
private MGLV1_DEV01Entities db = new MGLV1_DEV01Entities();
private List<KeyValuePair<string, List<FUNC_LIST_USERS_Result>>> list_user;
private List<FUNC_LIST_USERS_Result> list_users;
private List<FUNC_LIST_GROUPE_Result> list_groupe;
private List<KeyValuePair<string,List<FUNC_LIST_Module_Result>>> list_module;
private List<FUNC_LIST_Module_Result> list_modules;
// GET: Users
public ActionResult Index()
{
list_groupe = db.FUNC_LIST_GROUPE().ToList();
ViewBag.list_modules = list_modules = db.FUNC_LIST_ALL_Module().ToList();
ViewBag.list_u = list_users = db.FUNC_LIST_ALL_USERS().ToList();
list_module = new List<KeyValuePair<string, List<FUNC_LIST_Module_Result>>>();
list_user = new List<KeyValuePair<string, List<FUNC_LIST_USERS_Result>>>();
foreach (FUNC_LIST_GROUPE_Result res in list_groupe)
{
list_module.Add(new KeyValuePair<string, List<FUNC_LIST_Module_Result>>(res.GROUP_NOM, db.FUNC_LIST_Module(res.GROUP_NOM).ToList()));
list_user.Add(new KeyValuePair<string, List<FUNC_LIST_USERS_Result>>(res.GROUP_NOM,db.FUNC_LIST_USERS(res.GROUP_NOM).ToList() ) );
}
ViewBag.list_module = list_module;
ViewBag.list_user = list_user;
//System.Diagnostics.Debug.WriteLine("cred =" + HttpContext.Application["users"].ToString());
try
{
if (HttpContext.Application["users"].ToString().Equals("False"))
return RedirectToAction("Nocredential", "Home");
else
return View();
}
catch(Exception e)
{
return RedirectToAction("Index", "Home");
}
}
public ActionResult AjouterUtilisateur()
{//line 54///
string usernames = Request.Form["userschoi"];
string newusername = Request.Form["username"];
string groupename = Request.Form["groupename"];
string[] users = usernames.Split(',');
//System.Diagnostics.Debug.WriteLine("usernames:" + usernames+ " ////// newusername= "+ newusername);
db.PS_DELETE_USER(groupename);
for(int i = 0; i<users.Length; i++)
{
db.PS_ADD_USER_TO_GROUPE(groupename, users[i]);
}
if(newusername!=null && !newusername.Equals(""))
{
db.PS_ADD_USER(newusername);
db.PS_ADD_USER_TO_GROUPE(groupename, newusername);
}
list_groupe = db.FUNC_LIST_GROUPE().ToList();
ViewBag.list_modules = list_modules = db.FUNC_LIST_ALL_Module().ToList();
ViewBag.list_u = list_users = db.FUNC_LIST_ALL_USERS().ToList();
list_module = new List<KeyValuePair<string, List<FUNC_LIST_Module_Result>>>();
list_user = new List<KeyValuePair<string, List<FUNC_LIST_USERS_Result>>>();
foreach (FUNC_LIST_GROUPE_Result res in list_groupe)
{
list_module.Add(new KeyValuePair<string, List<FUNC_LIST_Module_Result>>(res.GROUP_NOM, db.FUNC_LIST_Module(res.GROUP_NOM).ToList()));
list_user.Add(new KeyValuePair<string, List<FUNC_LIST_USERS_Result>>(res.GROUP_NOM, db.FUNC_LIST_USERS(res.GROUP_NOM).ToList()));
}
ViewBag.list_module = list_module;
ViewBag.list_user = list_user;
try
{
if (HttpContext.Application["users"].ToString().Equals("False"))
return RedirectToAction("Nocredential", "Home");
else
return PartialView();
}
catch (Exception e)
{
return RedirectToAction("Index", "Home");
}
}
public ActionResult Supprimergroupe(string nom)
{
if (nom != null)
db.PS_DELETE_GROUP(nom);
list_groupe = db.FUNC_LIST_GROUPE().ToList();
ViewBag.list_modules = list_modules = db.FUNC_LIST_ALL_Module().ToList();
ViewBag.list_u = list_users = db.FUNC_LIST_ALL_USERS().ToList();
list_module = new List<KeyValuePair<string, List<FUNC_LIST_Module_Result>>>();
list_user = new List<KeyValuePair<string, List<FUNC_LIST_USERS_Result>>>();
foreach (FUNC_LIST_GROUPE_Result res in list_groupe)
{
list_module.Add(new KeyValuePair<string, List<FUNC_LIST_Module_Result>>(res.GROUP_NOM, db.FUNC_LIST_Module(res.GROUP_NOM).ToList()));
list_user.Add(new KeyValuePair<string, List<FUNC_LIST_USERS_Result>>(res.GROUP_NOM, db.FUNC_LIST_USERS(res.GROUP_NOM).ToList()));
}
ViewBag.list_module = list_module;
ViewBag.list_user = list_user;
try
{
if (HttpContext.Application["users"].ToString().Equals("False"))
return RedirectToAction("Nocredential", "Home");
else
return PartialView();
}
catch (Exception e)
{
return RedirectToAction("Index", "Home");
}
}
public ActionResult Ajoutergroupe()
{
string groupename = Request.Form["groupename"];
if(groupename!=null)
db.PS_ADD_GROUPE(groupename);
list_groupe = db.FUNC_LIST_GROUPE().ToList();
ViewBag.list_modules = list_modules = db.FUNC_LIST_ALL_Module().ToList();
ViewBag.list_u = list_users = db.FUNC_LIST_ALL_USERS().ToList();
list_module = new List<KeyValuePair<string, List<FUNC_LIST_Module_Result>>>();
list_user = new List<KeyValuePair<string, List<FUNC_LIST_USERS_Result>>>();
foreach (FUNC_LIST_GROUPE_Result res in list_groupe)
{
list_module.Add(new KeyValuePair<string, List<FUNC_LIST_Module_Result>>(res.GROUP_NOM, db.FUNC_LIST_Module(res.GROUP_NOM).ToList()));
list_user.Add(new KeyValuePair<string, List<FUNC_LIST_USERS_Result>>(res.GROUP_NOM, db.FUNC_LIST_USERS(res.GROUP_NOM).ToList()));
}
ViewBag.list_module = list_module;
ViewBag.list_user = list_user;
try
{
if (HttpContext.Application["users"].ToString().Equals("False"))
return RedirectToAction("Nocredential", "Home");
else
return PartialView();
}
catch (Exception e)
{
return RedirectToAction("Index", "Home");
}
}
public ActionResult AjouterModule()
{
string groupename = Request.Form["groupename"];
string modules = Request.Form["moduleschoi"];
string[] module = modules.Split(',');
for(int i = 0; i < module.Length; i++)
{
db.PS_ADD_GROUPE_TO_MOD(groupename, module[i]);
}
list_groupe = db.FUNC_LIST_GROUPE().ToList();
ViewBag.list_modules = list_modules = db.FUNC_LIST_ALL_Module().ToList();
ViewBag.list_u = list_users = db.FUNC_LIST_ALL_USERS().ToList();
list_module = new List<KeyValuePair<string, List<FUNC_LIST_Module_Result>>>();
list_user = new List<KeyValuePair<string, List<FUNC_LIST_USERS_Result>>>();
foreach (FUNC_LIST_GROUPE_Result res in list_groupe)
{
list_module.Add(new KeyValuePair<string, List<FUNC_LIST_Module_Result>>(res.GROUP_NOM, db.FUNC_LIST_Module(res.GROUP_NOM).ToList()));
list_user.Add(new KeyValuePair<string, List<FUNC_LIST_USERS_Result>>(res.GROUP_NOM, db.FUNC_LIST_USERS(res.GROUP_NOM).ToList()));
}
ViewBag.list_module = list_module;
ViewBag.list_user = list_user;
try
{
if (HttpContext.Application["users"].ToString().Equals("False"))
return RedirectToAction("Nocredential", "Home");
else
return PartialView();
}
catch (Exception e)
{
return RedirectToAction("Index", "Home");
}
}
public ActionResult SupprimerModule(string nom , string groupename)
{
if (nom != null && groupename != null)
db.PS_DELETE_MOD_GROUP(groupename, nom);
list_groupe = db.FUNC_LIST_GROUPE().ToList();
ViewBag.list_modules = list_modules = db.FUNC_LIST_ALL_Module().ToList();
ViewBag.list_u = list_users = db.FUNC_LIST_ALL_USERS().ToList();
list_module = new List<KeyValuePair<string, List<FUNC_LIST_Module_Result>>>();
list_user = new List<KeyValuePair<string, List<FUNC_LIST_USERS_Result>>>();
foreach (FUNC_LIST_GROUPE_Result res in list_groupe)
{
list_module.Add(new KeyValuePair<string, List<FUNC_LIST_Module_Result>>(res.GROUP_NOM, db.FUNC_LIST_Module(res.GROUP_NOM).ToList()));
list_user.Add(new KeyValuePair<string, List<FUNC_LIST_USERS_Result>>(res.GROUP_NOM, db.FUNC_LIST_USERS(res.GROUP_NOM).ToList()));
}
ViewBag.list_module = list_module;
ViewBag.list_user = list_user;
try
{
if (HttpContext.Application["users"].ToString().Equals("False"))
return RedirectToAction("Nocredential", "Home");
else
return PartialView();
}
catch (Exception e)
{
return RedirectToAction("Index", "Home");
}
}
}
}
So if someone can help me with that issue please!!! Also I've a seconde question is it normale that in the error text it shows me my local DEV folder even if it was run on the server (IIS8) and it's not the same path!
Oh!! I'm pretty sure that the NULLREFERENCEEXCEPTION is not due to some thing in the code because the code works fine on local environment with VS2015 - VS2013 as well , but not working on deployment servers(WS2012 and WS2008R2 that's were I've tested it so i can't tell if it works fine on other WS !). The seconde reason that make me see that is the error message that I get from server, it shows the local path on my machine were I've developed the application and not the path to the server repository were the application was put on and I think that is the problem but I can't find a reason to that.
So if you have any ideas of suggestion that can may be help me thanks for sharing it that will be greatly helpfull!