Why isn't MVC using Error.aspx? - asp.net-mvc

I'm trying to add some security to my ASP.NET 1.0 MVC app (VB), but I can't get it to work. At the top of my controller, I've got:
<HandleError()> _
Public Class HomeController
I'm overriding OnActionExecuting and throwing a SecurityException if the user is not in the proper role.
Everything I've read states that this should by default look for Error.aspx first in the current folder (Home) then in the Shared folder. I've got Error.aspx in both folders, and all I'm getting is a "Security Exception" yellow screen of death.
What am I missing?

do you have customErrors=On in your web.config
here

Do you have in your web.config? If mode="Off" or if you're accessing the site from the same box and mode="RemoteOnly", the debug page is shown instead of the error.aspx view.
If this is not the case, try creating an action on a controller that returns View("Error") and see what happens. I just had this problem recently and it was due to an error in the Error.aspx view itself. Rather than tell you there's a problem with the error view, the framework just goes ahead and displays the YSOD with the original error information.

Related

"Incorrect link" in episerver 7 when doing project as MVC

I've just created a new EpiServer 7 MVC project and created my first pagetype and page, the start page. In admin mode I can see the start page and if I single step in the start page controller I can see that "currentPage" has values.
BUT if I go to the page in the normal mode (not in edit in admin) I just get the "Incorrect link". If I single step I also see that "currentPage" is null in the controller. I thinks it's weird that EpiServer succeds in calling the right controller and action and then not being able to render it (it finds the view as well). I have no clue what's going on. I can't see any differences from how I've set up previous sites that works.
The exception is
Exception details:
HttpException: Not Found
Http status:
404 NotFound
If I create a project with webforms (no MVC) it works but it is when I merge a MVC project into the EPI-project this happens.
I have no clue what's wrong so thank you for answers!
I just had this problem with a new mvc site. After bending my brain for a couple of hours I found that although I had created a start page, I hadn't published it. After publishing the problem disappeared. Oh my...

Error.aspx - how to turn off?

I have my Error.aspx being loaded upon a server error but the problem is it has no information on it and I can't track down how or why it is being loaded. I searched my project for "Error.aspx" and nothing is coming up. How do you get a stack trace or something that is half way useful?
Thanks
Are you using a HandleError attribute on any of your controllers? If this attribute is present, when an unhandled exception occurs ASP.NET MVC will look for a view named Error.aspx in the controller's view folder. If it doesn't find one it then looks in the shared view folders. If you have default controllers in your project (ie. HomeController, AccountController) then you'll notice that they have the attribute.
Look in your web.config file for the <customErrors> element.
It probably specifies defaultRedirect="Error.aspx" and mode="On". Set mode="Off" or create an error page.
Read the MSDN docs: customErrors Element (ASP.NET Settings Schema)
Note: It is also possible that the <customErrors> element is being inherited from a .config file higher up at global server level (one of the root web.config files or machine.config). Check these if you cannot find <customErrors> in your application web.config file.

How to use [HandleError] without Master Page

I am trying to use [HandleError] in MVC to redirect any un-handled exceptions to the "Error.aspx" page in the "Shared" folder. By default the Visual Studio 2010 MVC2 template creates a simple MVC application with this function. It works fine.
But the Error.aspx file created by default uses "Site.Master". But I do not want to use master page in my application. I deleted default "Error.aspx" and added my own. But it simply does not work. Anyone has any idea on how to use [HandleError] without Master page?
Thanks ...
Put your custome Error.aspx or your custome error page in shared views
[HandleError(View = "Error")] // Or your custome error page name

How can I get 404 to work with Elmah and the HandleErrorAttribute written for Elmah in asp.net mvc?

I have implemented Elmah in one of my ASP.NET MVC projects. In addition I did the following:
I implemented the ElmahHandleErrorAttribute written by Atif Aziz in this post
I added the attribute to all my controllers
I have setup Elmah to filter out 404 errors since I do not want to log those
I added an Error.aspx view in the Shared folder that I wish to use for all my errors.
My customErrors in the Web.Config are turned on and I have not specifed any error pages in it as I shouldn't have to.
In one of my controllers I have the following code:
if (model == null)
throw new HttpException((int)HttpStatusCode.NotFound, "Project not found");
I simply want to display a 404 if a record can not be found in the database. For some reason my Error.aspx page will not display for a 404 error. Instead it displays the generic asp.net "the resource can not be found" page. I have tried to remove the 404 filter setup in Elmah but that does not change anything.
The interesting part is if I change the error from NotFound to say InternalServerError the Error.aspx page shows up just fine.
Does anyone have any pointers as to why this is?
I have not used Elmah beyond creating a sample app - but maybe because a 404 is not application error? If my understanding is correct, a 404 error gets pushed back to IIS which in turn displays the error message you are seeing. Also, I believe that the web.coin
If i understand correctly, you may want to amend your approach and build use this instead or set the Response.StatusCode to 404 (Check out Jeff's answer in the linked question)

MVC3 Razor view engine, error when creating a partial view

I'm evaluating MVC 3 and Razor. All was going well until I tried right clicking on Views\Shared and Add..View... I check the 'Create a partial' checkbox, strongly typed view, choose an entity, Razor, Empty... When I press OK, I get a huge error. Template Processing resulted in 1 Errors. The following exception was thrown: System.IO.FileNotFoundException: Could not load file or assembly 'Domain, Version-1.0.0.0... Trying this on a coworkers machine gave me no problems. We have the same version of MVC 3 installed. Any ideas why her's works just fine but I am getting this error? I have tried running as Administrator as well. Still no luck. Oddly if I uncheck strongly typed view, the partial view is created without a problem. Does anyone know how I can remedy this?
Thanks For any tips or help,
~ck in San Diego
I'm new to this and have the same issue. A workaround seems to be to remove the reference, create the partial view and than add the reference again. So it seems to be something inside this reference (corrupt).

Resources