MVC :: Derive From ControllerBase Or ControllerActionInvoker ?
May 21, 2010I am tryng to decide upon adding custom data to the ViewState dictionary by either deriving from ControllerBase or deriving from ControllerActionInvoker.
View 3 RepliesI am tryng to decide upon adding custom data to the ViewState dictionary by either deriving from ControllerBase or deriving from ControllerActionInvoker.
View 3 RepliesFor the heck of it, I decided to run my ASP.NET MVC 2 app in VS2010 with first chance exceptions enabled. I noticed a first chance exception in our custom ControllerActionInvoker. It appears to be non-fatal but seems to happen frequently. Concerned this could be slowing the web app down.
[Code]....
I have a question. How do I correctly derive from a script control? Especially how to correctly define the script descriptors.
Let's say, I have a MyScriptControl class implementing IScriptControl:
[Code]....
In the derived class, how Do I correctly overwrite the GetScriptDescriptors method? Should I just call base.GetScriptDescriptors, enumerate through them and exchange the Type name everywhere? Or is there a more clean feeling approach to that?
Not sure if the derived page is actually relevant to the problem here, but ran into an interesting gotcha on some code I'm working through at the moment.
I have a custom masterpage class, which derives from System.Web.UI.MasterPage so that it can be extended with additional useful properties. The page that that uses this masterpage has a declaration at the top (note the Page Title being set).
<%@ Page Language="C#" MasterPageFile="~/MasterPages/Landing.master" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" Title="Welcome to the site" %>
In addition, the master page has stylesheet references in the head which are pulled from a CDN that is defined in a config file.
<head id="Head1" runat="server">
<link rel="stylesheet" type="text/css" href="<%= CDN %>/css/main.css" />
</head>
Now the example above obviously doesn't work, because the runat attribute in the head container means that the codeblock in the the link is static text, and renders as is, in the resulting html.
If I remove the runat attribute from head, the CDN works, but now I notice that the Title is no longer being set. If I debug, and try to access Page.Title in the Immediate Window, I get an exception:
// Using the Title property of Page requires a header control on the page. (e.g. <head runat="server" />).
So, is there a way to get the Page Title from the declaration, put my own title placeholder in the head and set it from the master page code-behind, or, is there a better way to dynamically set the CDN domain for the stylesheets? The only way I think I can do that is to build the entire html link tag(s) and append it to the header control, but I thought there might be a more elegant solution, so I'm asking here first.
My question is similar to "ASP.NET 2 projects to share same files", but with an ASP.NET MVC slant.Basically, we have two sites, one being based mostly on the other (roughly 90% views, controllers, images, in the second are identical to the first). However, in some cases, the views may be different, or a controller in the second site may be different to the first.Are there any simple ways of achieving this in ASP.NET MVC?So far, we've looked at using linked files to have two totally seperate projects where the second project shares the files it needs from the first.One problem with this approach is that most pages in the second project don't literally exist in the virtual directory, it makes debugging a pain - you have to publish in order to generate the files so you can debug.
View 5 Replies