Skip to content

Commit d1eef46

Browse files
committed
Added script to copy dlls to where I need them. Reviewed and modified logger and exception filter for better messaging.
1 parent f393424 commit d1eef46

File tree

12 files changed

+179
-158
lines changed

12 files changed

+179
-158
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ ClientBin/
190190
*.publishsettings
191191
node_modules/
192192
orleans.codegen.cs
193+
*.bat
193194

194195
# RIA/Silverlight projects
195196
Generated_Code/

IoCContainers/MultiTenancyFramework.SimpleInjector/MultiTenancyFramework.SimpleInjector.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
<None Include="packages.config" />
7171
</ItemGroup>
7272
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
73+
<PropertyGroup>
74+
<PostBuildEvent>call "$(SolutionDir)postbuilds.bat" $(TargetPath) $(TargetName) $(TargetFileName) $(ConfigurationName)</PostBuildEvent>
75+
</PropertyGroup>
7376
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7477
Other similar extension points exist, see Microsoft.Common.targets.
7578
<Target Name="BeforeBuild">

MVC5/MultiTenancyFramework.Mvc.NHibernate/MultiTenancyFramework.Mvc.NHibernate.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@
101101
</ItemGroup>
102102
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
103103
<PropertyGroup>
104-
<PostBuildEvent>
105-
</PostBuildEvent>
104+
<PostBuildEvent>call "$(SolutionDir)postbuilds.bat" $(TargetPath) $(TargetName) $(TargetFileName) $(ConfigurationName)</PostBuildEvent>
106105
</PropertyGroup>
107106
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
108107
Other similar extension points exist, see Microsoft.Common.targets.

MVC5/MultiTenancyFramework.Mvc/MultiTenancyFramework.Mvc.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@
187187
<None Include="packages.config" />
188188
</ItemGroup>
189189
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
190+
<PropertyGroup>
191+
<PostBuildEvent>call "$(SolutionDir)postbuilds.bat" $(TargetPath) $(TargetName) $(TargetFileName) $(ConfigurationName)</PostBuildEvent>
192+
</PropertyGroup>
190193
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
191194
Other similar extension points exist, see Microsoft.Common.targets.
192195
<Target Name="BeforeBuild">

MVC5/MultiTenancyFramework.Mvc/MvcUtils/ErrorMessageModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,21 @@ public ErrorMessageModel(Exception ex, bool renderErrorPageFully = false)
8686
public ErrorMessageModel(Exception ex, string controllerName, string actionName, bool renderErrorPageFully = false)
8787
: base(ex, controllerName, actionName)
8888
{
89+
var context = System.Web.HttpContext.Current;
8990
if (string.IsNullOrWhiteSpace(FromUrl))
9091
{
91-
var routes = System.Web.HttpContext.Current.Request.RequestContext.RouteData.Values;
92-
FromUrl = $"/{routes["institution"]}/{routes["area"]}/{routes["controller"]}/{routes["action"]}";
92+
FromUrl = context.Request.RawUrl;
9393
}
9494
RenderErrorPageFully = renderErrorPageFully;
9595
ExceptionType = ex.GetType();
9696
StackTrace = ex.StackTrace;
9797
if (string.IsNullOrWhiteSpace(StackTrace))
9898
{
99-
ErrorMessage = WebUtility.HtmlDecode(ex.GetFullExceptionMessage());
99+
ErrorMessage = WebUtility.HtmlDecode(ex.GetFullExceptionMessage(context: context));
100100
}
101101
else
102102
{
103-
ErrorMessage = ex.GetFullExceptionMessage();
103+
ErrorMessage = ex.GetFullExceptionMessage(context: context);
104104
}
105105
if (ExceptionType == typeof(GeneralException))
106106
{

MVC5/MultiTenancyFramework.Mvc/MvcUtils/GlobalExceptionFilterAttribute.cs

Lines changed: 96 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -18,118 +18,123 @@ public void OnException(ExceptionContext filterContext)
1818
if (!filterContext.ExceptionHandled)
1919
{
2020
filterContext.ExceptionHandled = true;
21-
var values = filterContext.RouteData.Values;
22-
var Logger = Utilities.Logger;
23-
string instCode = Convert.ToString(values["institution"]);
24-
string area = Convert.ToString(values["area"]);
25-
string controller = Convert.ToString(values["controller"]);
26-
string action = Convert.ToString(values["action"]);
27-
var urlAccessed = string.Format("{0}/{1}/{2}/{3}", instCode, area, controller, action);
28-
Logger.Log(new GeneralException(string.Format("Crash from {0}", urlAccessed), filterContext.Exception));
29-
30-
bool doLogout = false;
21+
bool isFatal = false;
3122
try
3223
{
33-
var _instCode = WebUtilities.InstitutionCode ?? Utilities.INST_DEFAULT_CODE;
34-
if (!instCode.Equals(_instCode, StringComparison.OrdinalIgnoreCase))
24+
bool doLogout = false;
25+
var values = filterContext.RouteData.Values;
26+
string instCode = Convert.ToString(values["institution"]);
27+
try
3528
{
36-
instCode = Utilities.INST_DEFAULT_CODE;
37-
doLogout = true;
29+
var _instCode = WebUtilities.InstitutionCode ?? Utilities.INST_DEFAULT_CODE;
30+
if (!instCode.Equals(_instCode, StringComparison.OrdinalIgnoreCase))
31+
{
32+
instCode = Utilities.INST_DEFAULT_CODE;
33+
doLogout = true;
34+
}
3835
}
39-
}
40-
catch (LogOutUserException)
41-
{
42-
doLogout = true;
43-
}
44-
catch (Exception) //(GeneralException ex) when (ex.ExceptionType == ExceptionType.UnidentifiedInstitutionCode)
45-
{
46-
instCode = Utilities.INST_DEFAULT_CODE;
47-
}
48-
49-
// When view is not found, it usually throws
50-
//Exception Details: System.InvalidOperationException:
51-
// The view '~/Views/my-category/my-article-with-long-name.aspx' or its master could not be found. The following locations were searched: ~/Views/my-category/my-article-with-long-name.aspx
52-
if (filterContext.Exception is InvalidOperationException && filterContext.Exception.Message.Contains("The view '~/Views"))
53-
{
54-
Logger.Log(filterContext.Exception, true);
55-
filterContext.Result = MvcUtility.GetPageResult("ViewNotFound", "Error", "", instCode);
56-
return;
57-
}
58-
59-
var genEx = filterContext.Exception as GeneralException;
60-
if (genEx != null)
61-
{
62-
if (genEx.ExceptionType == ExceptionType.UnidentifiedInstitutionCode)
36+
catch (LogOutUserException)
6337
{
64-
instCode = Utilities.INST_DEFAULT_CODE;
65-
filterContext.Controller.TempData[ErrorMessageModel.ErrorMessageKey] = new ErrorMessageModel("Invalid Url. Please cross-check.", controller, action)
66-
{
67-
ErrorType = ExceptionType.UnidentifiedInstitutionCode,
68-
AreaName = area,
69-
FromUrl = urlAccessed,
70-
ResponseCode = HttpStatusCode.NotFound,
71-
};
38+
doLogout = true;
7239
}
73-
else if (genEx.ExceptionType == ExceptionType.DatabaseRelated)
40+
catch (Exception) //(GeneralException ex) when (ex.ExceptionType == ExceptionType.UnidentifiedInstitutionCode)
7441
{
75-
filterContext.Controller.TempData[ErrorMessageModel.ErrorMessageKey] = new ErrorMessageModel("A database error has occurred. Contact the administrator", controller, action)
76-
{
77-
ErrorType = ExceptionType.DatabaseRelated,
78-
AreaName = area,
79-
FromUrl = urlAccessed,
80-
ResponseCode = HttpStatusCode.InternalServerError,
81-
};
42+
instCode = Utilities.INST_DEFAULT_CODE;
8243
}
83-
else
44+
45+
// When view is not found, it usually throws
46+
//Exception Details: System.InvalidOperationException:
47+
// The view '~/Views/my-category/my-article-with-long-name.aspx' or its master could not be found. The following locations were searched: ~/Views/my-category/my-article-with-long-name.aspx
48+
if (filterContext.Exception is InvalidOperationException && filterContext.Exception.Message.Contains("The view '~/Views"))
8449
{
85-
filterContext.Controller.TempData[ErrorMessageModel.ErrorMessageKey] = new ErrorMessageModel(genEx, controller, action)
86-
{
87-
AreaName = area,
88-
FromUrl = urlAccessed
89-
};
50+
isFatal = true;
51+
filterContext.Result = MvcUtility.GetPageResult("ViewNotFound", "Error", "", instCode);
52+
return;
9053
}
91-
filterContext.Result = MvcUtility.GetPageResult("Index", "Error", "", instCode);
92-
return;
93-
}
9454

95-
if (doLogout || filterContext.Exception is LogOutUserException)
96-
{
97-
WebUtilities.LogOut();
98-
filterContext.Result = MvcUtility.GetLoginPageResult(instCode);
99-
}
100-
else
101-
{
102-
var dbExType = typeof(System.Data.Common.DbException);
103-
if (dbExType.IsAssignableFrom(filterContext.Exception.GetType())
104-
|| (filterContext.Exception.GetBaseException() != null && dbExType.IsAssignableFrom(filterContext.Exception.GetBaseException().GetType())))
55+
var urlAccessed = filterContext.RequestContext.HttpContext.Request.RawUrl; // string.Format("/{0}{1}/{2}/{3}", instCode, string.IsNullOrWhiteSpace(area) ? "" : ("/" + area), controller, action);
56+
57+
string area = Convert.ToString(values["area"]);
58+
string controller = Convert.ToString(values["controller"]);
59+
string action = Convert.ToString(values["action"]);
60+
var genEx = filterContext.Exception as GeneralException;
61+
if (genEx != null)
10562
{
106-
filterContext.Controller.TempData[ErrorMessageModel.ErrorMessageKey] = new ErrorMessageModel("A database error has occurred. Contact the administrator", controller, action)
63+
if (genEx.ExceptionType == ExceptionType.UnidentifiedInstitutionCode)
10764
{
108-
ErrorType = ExceptionType.DatabaseRelated,
109-
AreaName = area,
110-
FromUrl = urlAccessed,
111-
ResponseCode = HttpStatusCode.InternalServerError,
112-
};
65+
instCode = Utilities.INST_DEFAULT_CODE;
66+
filterContext.Controller.TempData[ErrorMessageModel.ErrorMessageKey] = new ErrorMessageModel("Invalid Url. Please cross-check.", controller, action)
67+
{
68+
ErrorType = ExceptionType.UnidentifiedInstitutionCode,
69+
AreaName = area,
70+
FromUrl = urlAccessed,
71+
ResponseCode = HttpStatusCode.NotFound,
72+
};
73+
}
74+
else if (genEx.ExceptionType == ExceptionType.DatabaseRelated)
75+
{
76+
filterContext.Controller.TempData[ErrorMessageModel.ErrorMessageKey] = new ErrorMessageModel("A database error has occurred. Contact the administrator", controller, action)
77+
{
78+
ErrorType = ExceptionType.DatabaseRelated,
79+
AreaName = area,
80+
FromUrl = urlAccessed,
81+
ResponseCode = HttpStatusCode.InternalServerError,
82+
};
83+
}
84+
else
85+
{
86+
filterContext.Controller.TempData[ErrorMessageModel.ErrorMessageKey] = new ErrorMessageModel(genEx, controller, action)
87+
{
88+
AreaName = area,
89+
FromUrl = urlAccessed
90+
};
91+
}
92+
filterContext.Result = MvcUtility.GetPageResult("Index", "Error", "", instCode);
93+
return;
11394
}
114-
else if (filterContext.Exception is HttpAntiForgeryException)
95+
96+
if (doLogout || filterContext.Exception is LogOutUserException)
11597
{
116-
filterContext.Controller.TempData[ErrorMessageModel.ErrorMessageKey] = new ErrorMessageModel("Looks like this is a cross-site request forgery. We can't find the token.", controller, action)
117-
{
118-
AreaName = area,
119-
FromUrl = urlAccessed
120-
};
98+
WebUtilities.LogOut();
99+
filterContext.Result = MvcUtility.GetLoginPageResult(instCode);
121100
}
122101
else
123102
{
124-
filterContext.Controller.TempData[ErrorMessageModel.ErrorMessageKey] = new ErrorMessageModel(filterContext.Exception, controller, action)
103+
var dbExType = typeof(System.Data.Common.DbException);
104+
if (dbExType.IsAssignableFrom(filterContext.Exception.GetType())
105+
|| (filterContext.Exception.GetBaseException() != null && dbExType.IsAssignableFrom(filterContext.Exception.GetBaseException().GetType())))
125106
{
126-
AreaName = area,
127-
FromUrl = urlAccessed
128-
};
107+
filterContext.Controller.TempData[ErrorMessageModel.ErrorMessageKey] = new ErrorMessageModel("A database error has occurred. Contact the administrator", controller, action)
108+
{
109+
ErrorType = ExceptionType.DatabaseRelated,
110+
AreaName = area,
111+
FromUrl = urlAccessed,
112+
ResponseCode = HttpStatusCode.InternalServerError,
113+
};
114+
}
115+
else if (filterContext.Exception is HttpAntiForgeryException)
116+
{
117+
filterContext.Controller.TempData[ErrorMessageModel.ErrorMessageKey] = new ErrorMessageModel("Looks like this is a cross-site request forgery. We can't find the token.", controller, action)
118+
{
119+
AreaName = area,
120+
FromUrl = urlAccessed
121+
};
122+
}
123+
else
124+
{
125+
filterContext.Controller.TempData[ErrorMessageModel.ErrorMessageKey] = new ErrorMessageModel(filterContext.Exception, controller, action)
126+
{
127+
AreaName = area,
128+
FromUrl = urlAccessed
129+
};
130+
}
131+
filterContext.Result = MvcUtility.GetPageResult("Index", "Error", "", instCode);
129132
}
130-
filterContext.Result = MvcUtility.GetPageResult("Index", "Error", "", instCode);
131133
}
132-
return;
134+
finally
135+
{
136+
Utilities.Logger.Log(filterContext.Exception, isFatal);
137+
}
133138
}
134139

135140
}

0 commit comments

Comments
 (0)