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
Related
I'm trying to add Help to my ASP.NET MVC project.
The "help" website contains static pages about the features in my ASP.NET application.
I have added the content for this website into my ASP.NET MVC project and have added a hyperlink that will open the Help in its own window.
However, when I try to access the content, the application attempts to route to the Help controller.
How do I display the help website within my MVC application?
I am not sure you can do this within the context of an MVC application. I would consider just building an empty controller with an Index action (HelpController -> public ActionResult Index()) and just return the view name (cshtml file), shouldn't be any reason you can't rename your static html file to cshtml even if you aren't using razor (although I am not 100% sure without trying that the extension change is necessary). Also I would argue that if this ever needs more functionality you have the scaffolding in place to make non-static mods. Disabling routing within the context of an MVC solution honestly doesn't make the most logical sense. The only other choice would be if you hosted it in a different IIS site (but I don't think I would recommend that unless you have a huge help library).
Use IgnoreRoute when you configre your routing, for example, create a folder "help" in your app's root. Then load it with all your html help files. Then to ignore that route:
routes.IgnoreRoute("help");
You should then be able to access it by http://myapp.com/help/whatever.html
I'm a total beginner so sorry in advance.
I used VS13 to build a MVC project and published it to my webspace. Now I'm unsure which file or path I need to specify in my forwarding config in order to open the website.
I tried
/Views/Shared
to get _Layout.cshtml and
/Views/Home
to get Index.cshtml but none of these are working. I also changed some admissions but it always shows me this
Forbidden - You don't have permission to access / on this server.
when I'm trying to open the website.
Any ideas on what I'm doing wrong?
With MVC You don't access views like traditional ASP.NET WebForms i.e. /path/to/view.aspx. Everything is handled via routing & controllers.
By default you will have a HomeController which will have an Index action which is invoked via a GET request. Assuming you haven't changed any of the default routing configuration you would just need to navigate to www.domainname.com/home to see your Index page.
The default routing configuration looks like /controller/action/parameters, MVC will always work this way unless you tell it different. If you don't pass a specific action (like I didn't with the home url) the Index action of the controller is assumed.
I am new to asp .net MVC. I am trying to implement SPA model for my new application. I am using asp .net web api in asp .net mvc4 project. I have only api controllers in my project. I dont have any MVC controllers.
I have deleted auto generated views from the views folder. I have created a index.cshtml page outside the views folder. This page is my layout page that renders other pages in it. I have set this page as startup page. And also i have commented out the default MVC route from routeconfig.cs file.
The problem is when i run the application, the index.cshtml does not render. I get an error saying "This type of page is not served - Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect."
Please help
Make sure you keep the root Views folder, and create a folder called Home within that. Place your Index.cshtml file within the Home folder.
Do not comment out the default MVC route. In MVC, you can't hit a view directly, as you do in WebForms, which is why you get the error when you try to hit Index.cshtml.
Make sure you have a HomeController within the root Controllers folder, with an action called Index that looks like this:
public ActionResult Index()
{
return View();
}
Your view should now render when you browse http://localhost/Home/Index or even just http://localhost as by default, the controller and action will be set to Home/Index.
I am working on an web application that uses themes and different master pages. Each master page is at the shared folder with their names; such as Shared\Themes\MyTheme\Site.master
and the views are at \ControllerName\ListUsers.aspx
In the controller; I call the view : return View("ListUsers",ThemeEngine.MasterPage,Model);
So far everything works fine; however when I try to call RenderPartial inside the ListUsers, I am getting usercontrol can't be found error because my user controls are at the master page folder such as \Shared\Themes\MyTheme\SingleUser.ascx
Is there a way to tell the framework to look for the user controls in a different folder than \Shared but \Shared\ThemeNAme etc...
Yep. You can specify the path to the View using the virtual root. There's nothing stopping you from passing in a full path.
return View("~/Shared/Themes/MyTheme/SingleUser.ascx");
How to change default view location scheme in 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.