Latest Updates: ASP.NET MVC RSS

  • Master does not have a definition for ViewData (ASP.NET MVC2)

    Phil Leggetter 12:05 pm on August 4, 2010 | 1 Permalink | Reply
    Tags: ASP.NET, ASP.NET MVC,

    I’m building an ASP.NET MVC2 web application and I was trying to access ViewData in my Site.Master page and I kept getting “master does not have a definition for ViewData”.

    <%= ViewData["topic"] %>

    The simple answer was that my Master Page was not an ASP.NET MVC2 master page. Somehow I had a standard master page.

    So, all I did was swap the existing page declaration

    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.Master.cs" Inherits="HubSubscriber.Views.Shared.Site" %>

    With an ASP.NET MVC2 declaration:

    <%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>

    And bingo! ViewData was now accessible from my master page.

    This post on Passing Data to View Master Pages may also be useful.

     
  • Windows Azure - 503 Service Unavailable

    Phil Leggetter 12:44 am on August 28, 2009 | 0 Permalink | Reply
    Tags: , ASP.NET MVC, ,

    I finally got around to trying out ASP.NET MVC and while I was at it I thought I’d also give Windows Azure a whirl. Windows Azure doesn’t support ASP.NET MVC out of the box but Jim over on MSDN Blogs has written up the details of how to get ASP.Net MVC Projects running on Windows Azure.

    Problem

    So, I followed the instruction from the blog and uploaded the package and configuration file, waited for the staging application to get into a runnable state, and clicked on the staging link…

    Windows Azure – 503 Service Unavailable

    Clearly not a good thing! In addition to this error I occasionally got a random network error or a full-on connection error reported by the browser.

    I tried googling for this error but there was nothing about this problem after deploying to the real Windows Azure hosting (the cloud). As far as I can tell there’s no way of getting any debug information or logs to work out what’s going wrong. Maybe this is something that Microsoft will add later on?

    Solution

    Then it struck me that I hadn’t actually set up any kind of TableStorage on my Windows Azure hosting so I removed all mentions of storage and database connections from the MVC application. This included editing Web.config and removing the following.

    • The <section name=”authenticationService” type=”System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” allowDefinition=”MachineToApplication” /> section element.
    • The <connectionStrings> element
    • The <membership>element
    • The <authentication mode=”Forms”> element
    • The <profile> element
    • The <roleManager>element

    Update: I’ve found that without the <authentication>element I started getting the error below so you may want to instead replace it with :

    CCT: Role instances did not start within the time allowed. Please try again. If you continue to encounter this behavior please try shutting down the Development Fabric.

    I’m guessing that not all of these elements actually need to be removed but doing so resulted in the MVC ASP.NET application working in Windows Azure.

    Update 2: ServiceDefinition.csdef

    If you happen to get network timeouts or 404 network connection issues it’s worth checking your ServiceDefinition.csdef to make sure that you’ve got port 80 configured. I noticed that mine had updated to port 8080 so obviously I couldn’t access the staging site on port 80 like I was trying. If you do have the port set to something else other than port 80 you can use that port to access your application but the ServiceDefinition.csdef does have a comment in there telling you your application should be on port 80 so you are probably best to stick with that.

    <!– Must use port 80 for http and port 443 for https when running in the cloud –>
    <InputEndpoint name=”HttpIn” protocol=”http” port=”80″ />

     
  • System.Security.SecurityException: That assembly does not allow partially trusted callers

    Phil Leggetter 12:51 am on August 26, 2009 | 1 Permalink | Reply
    Tags: , ASP.NET MVC, ,

    I was writing a Windows Azure ASP.NET MVC application and when making a call to a page I received the following exception:

    System.Security.SecurityException: That assembly does not allow partially trusted callers

    In my application I’m using Castle Windsor for dependency injection and when trying to resolve a service using:

    }

    IGravatar gravatar = MvcApplication.Container.Resolve<IGravatar>();

    I received this message. To solve things I needed to update the WebRole element in the ServiceDefinitions.csdef file so that enableNativeCodeExecution is enabled.

    <WebRole name=”TwitterGravatarMVC” enableNativeCodeExecution=”true”>

    I found the solution, detailed above, on the Azure Services Platform Developer Centre forum.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
esc
cancel