the topic error showing me when I am redirect the view page from controller.
Here is the full error
An unhandled exception occurred while processing the request.
InvalidOperationException: The view '~/Views/Udhyog/Services.cshtml' was not found. The following locations were searched:
~/Views/Udhyog/Services.cshtml
Here is my controller code
public virtual IActionResult Index()
{
return View("~/Views/Udhyog/Services.cshtml");
}
I am surprised that why this type of error is showing, because In views => Udhyog named one folder and in that I want to show the services.cshtml view page.
So, is there my code wrong or is there any another method to redirect the view page?
return View("../UdhyogMaster/Services");
Related
I have a controller which contains certain kinds of methods. This controller is housed in a separate assembly. The idea being that other APIs can then opt in if they want to use this functionality as unbound functions.
The problem is that if I don't implement this functionality with the ODataConventionModelBuilder OData returns the following error:
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
Inner Exception 1:
InvalidOperationException: The path template 'TestFunction' on the action 'TestFunction' in controller 'OptInFunctions' is not a valid OData path template. Resource not found for the segment 'TestFunction'
If I remove the ODataRouteAttribute from the functions then OData does not return an error during startup, but a 404 when I want to call the function.
My controller with the opt-in methods looks something like this:
public class OptInFunctions : ODataController
{
[HttpGet]
[ODataRoute("TestFunction")]
public ActionResult<bool> TestFunction()
{
return Ok(true);
}
}
How can I make an OData unbound function opt-in?
I've inherited a grails project in which an Error Controller is used.
Within the URLMappings there is the following entry:
"500"(controller: 'error', action:'error')
The specific errorController renders a specific view:
render view:'/error/prodError'
What I don't understand is how to bypass error controller for 500 errors and send to view /play/play but without removing the old one for other situations.
Even though I catch exceptions from the playService, I still get /error/prodError instead of /play/play.
I've debugged the code and seen that the render method is called twice. It is called once to go to /play/play but another time for /error/prodError when an exception is thrown in the service and the transaction is rolled back.
See playController excerpt below:
PlayController
try{
playService.play(parame:params} //Runtime exception thrown from playService.
//play is transactional
}
catch(Throwable t){
//Why isn't /play/play rendered?
//How do I pass errors to playservice for alert rendering?
render view: '/play/play',
model: [
domain: domain,
customer: customer,
game: game]
return
}
Update
Specifically, the errorController is entered because of an UnexpectedRollbackException that is the result of the rollback.
SO: How would someone go about not entering the ErrorController for a specific type of Exception that results from a specific Controller?
If you don't want to handle the error within a controller, you could render your (or any other) view with the following url mapping:
"500"(view:'/play/play')
If you need to handle individual exception you do it like this:
static mappings = {
.
.
.
"500"(controller: "error", action: "unexpectedRollback", exception: UnexpectedRollbackException)
"500"(controller: "errors", action: "nullPointer", exception: NullPointerException)
.
.
"500"(controller: 'error', action:'error')
}
As mentioned in docs you should avoid throwning exceptions from your error controller due to StackOverflowExceptions. I think it's not possible to divide between two exceptions of the same type but thrown from diffent controller.
If you handle the exception within your error controller you could try to set the response code directly. So - the url mapping may not handle your already handled exception.
My app: VS2010, MVC3, C#, latest ELMAH
Case: some errors happens (e.g. null reference), custom error page is shown (customErrors mode="On").
Task: allow admins (users in role Admins, ) view error detail from custom error page
Question: How to obtain/pass elmah error id to the custom error page view ?
Upd: Related answered question: ELMAH - Using custom error pages to collecting user feedback
Custom error page sample:
#model System.Web.Mvc.HandleErrorInfo
#{
ViewBag.Title = "Error";
}
<h2>
Error processing a request.
#if (User.IsInRole(MyAppNamespace.Constants.ROLE_ADMIN))
{
// where to obtain ELMAH error id to navigate to error details ?
// elmah/detail?id=291f5e83-5756-43bf-a889-07a548727da7
View error details
}
</h2>
It is an event in Elmah ErrorLog module, that can be handled in Global.asax.cs:
protected void ErrorLog_Logged(object sender, ErrorLoggedEventArgs args)
{
Session["ElmahId"] = args.Entry.Id;
}
Then we can use stored id to navigate to error (I am using Elmah.Mvc module that implements special controller instead of default elmah pages). In Error.cshtml:
#if (User.IsInRole(renweb.Constants.ROLE_ADMIN))
{
Error details
}
From what I know all Elmah errors are saved in a table called EMAH_Error.
So one thing you could do is to get the current date time when the error occurred and query the table for the records saved on that time give/take 1 minute. The query it will return the error saved with the appropriate time stamp that will also contain the ErrorId.
You can easily use EF or something else to create and entity ElmahError.
I have mvc 3 application which when a Standard generic throw new Exception is thrown in code the error page from Views\Shared\error.cshtml is shown. This is done by simply setting <customErrors mode="On"/>. (This is As expected and as Desired)
The application is using WCF services in middle tier which when these services generate FaultException MVC is not showing up the error page it is showing details of the web service call to the user on screen. All I want to do is handle the error in my code and show the user the Error.cshtml. I have tried changing global asax but this dosent work.
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
if (exception.GetType() == typeof(FaultException))
{
throw new Exception("There was a fault exception that i do not want to show details of to user.");
}
}
Try creating an ErrorController as asp.net MVC will try to resolve the link you specified in the web.config as {Controller}/{View} unless you specify it to ignore that page. Also, you may want to apply an attribute to handle exceptions instead.
You can also create a error controller/view and in your catch block redirect to the custom error page of your choosing
try
{
foo.bar()
}
catch(SpecificException)
{
RedirectToAction("500", "Error");
}
I am trying to implement Custom Error handling via Action Filter Attributes.
My code is as follows:
[HandleError (Order = 2)]
[HandleError (Order = 1, ExceptionType = typeof(NullReferenceException), View = "CustomError")]
public class ArticlesController : Controller
{
public object OhDearACrash()
{
throw new Exception("Oh Dear");
}
public ActionResult NullRefCrash()
{
throw new NullReferenceException();
}
public ActionResult ThrowNotImplemented()
{
throw new NotImplementedException();
}
OhDearACrash and ThrowNotImplemented are both picked up by [HandleError] which renders the error message via Error.aspx located in Views/Shared.
For example with OhDearACrash:
Message = <%= ViewData.Model.Exception.Message %>
renders
Message = Oh Dear
NullRefCrash is picked up by the [HandeError] that deals with an ExceptionType = typeof(NullReferenceException).
When CustomError attempts to render the error message using
Message = <%= ViewData.Model.Exception.Message %>
the ViewData.Model is null and an exception is raised
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
To create CustomError.aspx I copied Error.aspx and pasted to my newly created Views/Error and renamed to CustomView.aspx.
Since Error.aspx and CustomError.aspx are essentially the same how is this occuring?
Edit:
I created a Test Project that only contains the above and the CustomError.aspx view works perfectly fine - Is there anyway to debug my existing project to find the issue?
I just tried this on ASP.NET MVC 1.0 and I'm getting the correct behavior.
Is it possible that you have another filter somewhere else that is running and changing the error somehow?