mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Added easy way for user's to submit bug report if they see an error screen.
This commit is contained in:
parent
8859cbf0d5
commit
6708fc2de6
@ -124,6 +124,8 @@ namespace Teknik.Areas.Error.Controllers
|
||||
[AllowAnonymous]
|
||||
public ActionResult Http500(Exception exception)
|
||||
{
|
||||
Session["Exception"] = exception;
|
||||
|
||||
ViewBag.Title = "500 - " + Config.Title;
|
||||
ViewBag.Description = "Something Borked";
|
||||
|
||||
@ -141,6 +143,67 @@ namespace Teknik.Areas.Error.Controllers
|
||||
return View("~/Areas/Error/Views/Error/Http500.cshtml", model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult SubmitErrorReport(SubmitReportViewModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
string exceptionMsg = model.Exception;
|
||||
|
||||
// Try to grab the actual exception that occured
|
||||
object exceptionObj = Session["Exception"];
|
||||
if (exceptionObj != null)
|
||||
{
|
||||
Exception ex = (Exception) exceptionObj;
|
||||
exceptionMsg = string.Format(@"
|
||||
Exception: {0}
|
||||
|
||||
Source: {1}
|
||||
|
||||
Stack Trace:
|
||||
|
||||
{2}
|
||||
", ex.GetFullMessage(true), ex.Source, ex.StackTrace);
|
||||
}
|
||||
|
||||
// Let's also email the message to support
|
||||
SmtpClient client = new SmtpClient();
|
||||
client.Host = Config.ContactConfig.EmailAccount.Host;
|
||||
client.Port = Config.ContactConfig.EmailAccount.Port;
|
||||
client.EnableSsl = Config.ContactConfig.EmailAccount.SSL;
|
||||
client.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
client.UseDefaultCredentials = true;
|
||||
client.Credentials = new System.Net.NetworkCredential(Config.ContactConfig.EmailAccount.Username, Config.ContactConfig.EmailAccount.Password);
|
||||
client.Timeout = 5000;
|
||||
|
||||
MailMessage mail = new MailMessage(new MailAddress(Config.NoReplyEmail, Config.NoReplyEmail), new MailAddress(Config.SupportEmail, "Teknik Support"));
|
||||
mail.Sender = new MailAddress(Config.ContactConfig.EmailAccount.EmailAddress);
|
||||
mail.Subject = "[Exception] Application Exception Occured";
|
||||
mail.Body = @"
|
||||
An exception has occured at: " + model.CurrentUrl + @"
|
||||
|
||||
----------------------------------------
|
||||
User Message:
|
||||
|
||||
" + model.Message + @"
|
||||
|
||||
----------------------------------------
|
||||
" + exceptionMsg;
|
||||
mail.BodyEncoding = UTF8Encoding.UTF8;
|
||||
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Never;
|
||||
|
||||
client.Send(mail);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { error = "Error submitting report. Exception: " + ex.Message });
|
||||
}
|
||||
|
||||
return Json(new { result = "true" });
|
||||
}
|
||||
|
||||
private void LogError(LogLevel level, string message, Exception exception)
|
||||
{
|
||||
if (Request != null)
|
||||
|
@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Optimization;
|
||||
using Teknik.Configuration;
|
||||
using Teknik.Utilities;
|
||||
|
||||
namespace Teknik.Areas.Error
|
||||
{
|
||||
@ -41,6 +43,19 @@ namespace Teknik.Areas.Error
|
||||
new { controller = "Error", action = "Http500" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.ErrorController).Namespace }
|
||||
);
|
||||
context.MapSubdomainRoute(
|
||||
"Error.Action", // Route name
|
||||
new List<string>() { "error" }, // Subdomains
|
||||
new List<string>() { config.Host }, // domains
|
||||
"{action}", // URL with parameters
|
||||
new { controller = "Error", action = "Index" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.ErrorController).Namespace }
|
||||
);
|
||||
|
||||
// Register Bundles
|
||||
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/error", config.CdnHost).Include(
|
||||
"~/Scripts/bootbox/bootbox.min.js",
|
||||
"~/Areas/Error/Scripts/Error.js"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
49
Teknik/Areas/Error/Scripts/Error.js
Normal file
49
Teknik/Areas/Error/Scripts/Error.js
Normal file
@ -0,0 +1,49 @@
|
||||
$(document).ready(function() {
|
||||
$('#submitErrorReport').click(function() {
|
||||
bootbox.prompt({
|
||||
title: "Please enter any additional information that could help us",
|
||||
inputType: 'textarea',
|
||||
callback: function(result) {
|
||||
if (result) {
|
||||
errorMsg = $("#errorMsg").html();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: submitErrorReportURL,
|
||||
data: AddAntiForgeryToken({
|
||||
Message: result,
|
||||
Exception: errorMsg,
|
||||
CurrentUrl: window.location.href
|
||||
}),
|
||||
success: function(response) {
|
||||
if (response.result) {
|
||||
$("#top_msg").css('display', 'inline', 'important');
|
||||
$("#top_msg").html(
|
||||
'<div class="alert alert-info alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Thank you for your help! Feedback has been submitted.</div>');
|
||||
} else {
|
||||
$("#top_msg").css('display', 'inline', 'important');
|
||||
$("#top_msg")
|
||||
.html(
|
||||
'<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' +
|
||||
parseErrorMessage(response) +
|
||||
'</div>');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(".view-details-button").on("click",
|
||||
function() {
|
||||
var link = $(this);
|
||||
var linkText = link.text().toUpperCase();
|
||||
|
||||
if (linkText === "SHOW DETAILS") {
|
||||
link.text("Hide Details");
|
||||
} else {
|
||||
link.text("Show Details");
|
||||
};
|
||||
}
|
||||
);
|
||||
});
|
21
Teknik/Areas/Error/ViewModels/SubmitReportViewModel.cs
Normal file
21
Teknik/Areas/Error/ViewModels/SubmitReportViewModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Teknik.ViewModels;
|
||||
|
||||
namespace Teknik.Areas.Error.ViewModels
|
||||
{
|
||||
public class SubmitReportViewModel : ViewModelBase
|
||||
{
|
||||
[AllowHtml]
|
||||
public string Message { get; set; }
|
||||
|
||||
[AllowHtml]
|
||||
public string Exception { get; set; }
|
||||
|
||||
[AllowHtml]
|
||||
public string CurrentUrl { get; set; }
|
||||
}
|
||||
}
|
@ -1,19 +1,40 @@
|
||||
@model Teknik.Areas.Error.ViewModels.ErrorViewModel
|
||||
@model Teknik.Areas.Error.ViewModels.ErrorViewModel
|
||||
|
||||
@using Teknik.Utilities
|
||||
|
||||
@Scripts.Render("~/bundles/error")
|
||||
<script>
|
||||
var submitErrorReportURL = '@Url.SubRouteUrl("error", "Error.Action", new { action = "SubmitErrorReport" })';
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="error-template text-center">
|
||||
<h1>Unexpected Error</h1>
|
||||
<div class="error-details">
|
||||
An unexpected error has occurred. Please contact the system administrator.
|
||||
<br />
|
||||
<br />
|
||||
<p>Uh oh! You aren't supposed to be seeing this. Something went horribly wrong.</p>
|
||||
<div class="error-actions">
|
||||
<a href="@Url.SubRouteUrl("www", "Home.Index")" class="btn btn-default btn-lg">
|
||||
<span class="glyphicon glyphicon-home"></span>
|
||||
Take Me Home
|
||||
</a>
|
||||
@if (Model != null && Model.Exception != null)
|
||||
{
|
||||
<div class="text-left">
|
||||
<div class="btn btn-primary btn-lg" id="submitErrorReport">
|
||||
<span class="fa fa-bug"></span>
|
||||
Submit Bug Report
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@if (Model != null && Model.Exception != null)
|
||||
{
|
||||
<br />
|
||||
<div class="show-more" id="view-details">
|
||||
<button role="button" class="btn btn-default btn-sm view-details-button" data-toggle="collapse" data-target="#errorMsg">Show Details</button>
|
||||
</div>
|
||||
<div class="text-left collapse" id="errorMsg">
|
||||
<br />
|
||||
<p>
|
||||
<b>Exception:</b> @Model.Exception.GetFullMessage(true)
|
||||
<br/>
|
||||
@ -25,17 +46,6 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<br />
|
||||
<div class="error-actions">
|
||||
<a href="@Url.SubRouteUrl("www", "Home.Index")" class="btn btn-primary btn-lg">
|
||||
<span class="glyphicon glyphicon-home"></span>
|
||||
Take Me Home
|
||||
</a>
|
||||
<a href="@Url.SubRouteUrl("contact", "Contact.Index")" class="btn btn-default btn-lg">
|
||||
<span class="glyphicon glyphicon-envelope"></span>
|
||||
Contact Support
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,7 +1,12 @@
|
||||
@model Teknik.Areas.Error.ViewModels.ErrorViewModel
|
||||
@model Teknik.Areas.Error.ViewModels.ErrorViewModel
|
||||
|
||||
@using Teknik.Utilities
|
||||
|
||||
@Scripts.Render("~/bundles/error")
|
||||
<script>
|
||||
var submitErrorReportURL = '@Url.SubRouteUrl("error", "Error.Action", new { action = "SubmitErrorReport" })';
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
@ -9,12 +14,28 @@
|
||||
<h1>Whoops!</h1>
|
||||
<h2>500 Server Error</h2>
|
||||
<div class="error-details">
|
||||
Sorry, a server error occured. Please contact an Administrator about this error.
|
||||
<br />
|
||||
<br />
|
||||
<p>Sorry, a server error occured. Please contact an Administrator about this error.</p>
|
||||
<div class="error-actions">
|
||||
<a href="@Url.SubRouteUrl("www", "Home.Index")" class="btn btn-default btn-lg">
|
||||
<span class="glyphicon glyphicon-home"></span>
|
||||
Take Me Home
|
||||
</a>
|
||||
@if (Model != null && Model.Exception != null)
|
||||
{
|
||||
<div class="text-left">
|
||||
<div class="btn btn-primary btn-lg" id="submitErrorReport">
|
||||
<span class="fa fa-bug"></span>
|
||||
Submit Bug Report
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@if (Model != null && Model.Exception != null)
|
||||
{
|
||||
<br />
|
||||
<div class="show-more" id="view-details">
|
||||
<button role="button" class="btn btn-default btn-sm view-details-button" data-toggle="collapse" data-target="#errorMsg">Show Details</button>
|
||||
</div>
|
||||
<div class="text-left collapse" id="errorMsg">
|
||||
<br />
|
||||
<p>
|
||||
<b>Exception:</b> @Model.Exception.GetFullMessage(true)
|
||||
<br/>
|
||||
@ -26,17 +47,6 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<br />
|
||||
<div class="error-actions">
|
||||
<a href="@Url.SubRouteUrl("www", "Home.Index")" class="btn btn-primary btn-lg">
|
||||
<span class="glyphicon glyphicon-home"></span>
|
||||
Take Me Home
|
||||
</a>
|
||||
<a href="@Url.SubRouteUrl("contact", "Contact.Index")" class="btn btn-default btn-lg">
|
||||
<span class="glyphicon glyphicon-envelope"></span>
|
||||
Contact Support
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,4 +1,4 @@
|
||||
html,
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
/* The html and body elements cannot have any padding or margin. */
|
||||
@ -320,7 +320,7 @@ textarea{
|
||||
.hero-widget label { font-size: 17px; }
|
||||
.hero-widget .options { margin-top: 10px; }
|
||||
|
||||
.error-template {padding: 40px 15px;text-align: center;}
|
||||
.error-template {text-align: center;}
|
||||
.error-actions {margin-top:15px;margin-bottom:15px;}
|
||||
.error-actions .btn { margin-right:10px; }
|
||||
|
||||
|
@ -250,6 +250,7 @@
|
||||
<Compile Include="Areas\Error\Controllers\ErrorController.cs" />
|
||||
<Compile Include="Areas\Error\ErrorAreaRegistration.cs" />
|
||||
<Compile Include="Areas\Error\ViewModels\ErrorViewModel.cs" />
|
||||
<Compile Include="Areas\Error\ViewModels\SubmitReportViewModel.cs" />
|
||||
<Compile Include="Areas\FAQ\Controllers\FAQController.cs" />
|
||||
<Compile Include="Areas\FAQ\FAQAreaRegistration.cs" />
|
||||
<Compile Include="Areas\FAQ\ViewModels\FAQViewModel.cs" />
|
||||
@ -406,6 +407,7 @@
|
||||
<Content Include="Areas\Blog\Content\Blog.css" />
|
||||
<Content Include="Areas\Blog\Scripts\Blog.js" />
|
||||
<Content Include="Areas\Contact\Scripts\Contact.js" />
|
||||
<Content Include="Areas\Error\Scripts\Error.js" />
|
||||
<Content Include="Areas\FAQ\Content\FAQ.css" />
|
||||
<Content Include="Areas\Help\Content\Help.css" />
|
||||
<Content Include="Areas\Home\Content\Home.css" />
|
||||
|
Loading…
Reference in New Issue
Block a user