Monorail on Shared Hosting

November 21, 2007 at 5:42 pm 18 comments

Since my last post i’ve been busy with a number of things. One of em was finishing a website I created using Monorail for someone i know. All worked well, made my life a bit easier… But then… the time came to publish the website to my shared hosting account (In this case: Brinkster). What happened is, which is not very strange in the end, after i published the website and tried to view it i got an exception: [SecurityException: That assembly does not allow partially trusted callers.] .. Basicly, the problem is, brinkster (and a lot of other shared hosting providers) let you run your ASP.NET application in a medium trust level. Took me a little time to figure this out, but in the end it turned out to be very easy. Read on to see what needed to be done.

Here are the steps you need to take if you encounter the same problem:

  1. Change your local web.config so that your local version also runs under medium trust level.
  2. <system.web><trust level=Medium/></system.web>

  3. If you do not have it already, install a SVN Client application so you can access Castle Project’s Subversion Repository. (I use TortoiseSVN)
  4. If you do not have it already, install nant (I use(d) version 0.85) which will allow you to build the Castle Project. (Also make sure your nant bin directory is referenced in your ‘path’ system variable)
  5. Check out the entire Castle Project repository to your local harddisk (Make sure you do not have any spaces in your path. So no “c:\program files\etc”. Don’t bother downloading the Source from the website without using SVN: it won’t build very easily… I didn’t get it to work anyhow.
  6. open a command line window
  7. Go to your local castle project version
  8. Build Castle Project by using the following command: nant -D:common.testrunner.enabled=false -D:assembly.al
    low-partially-trusted-callers=true
  9. In your Project/ website, reference to the DLL’s which are in your local Castle Project’s build directory.
  10. Make sure that in the configsection you defined you have the monorail section defined as the following:

<configSections><section name=monorail type=Castle.MonoRail.Framework.Configuration.MonoRailSectionHandler, Castle.MonoRail.Framework requirePermission=false /></configSections>Et voila, it should work now 🙂

Advertisements

Entry filed under: .NET, Software Development. Tags: , , , , .

The anatomy of a Facet based search engine – Part 1

18 Comments Add your own

  • 1. Vincent Hendriks  |  November 22, 2007 at 12:08 am

    Ah, almost forgot: A lot of shared hosting accounts like brinkster don’t allow you to use .castle or .rails extensions because they’re not mapped to ASP.NET by default. You should use .ashx extensions instead. 🙂

    Reply
  • 2. Patrick Steele  |  February 1, 2008 at 11:57 pm

    You rock! I already knew I had to re-compile MonoRail with the special flag for partially trusted callers, but I never saw that “requirePermission” flag in any of the docs. This was driving me crazy!

    Thanks!

    Reply
  • 3. Vincent Hendriks  |  February 4, 2008 at 1:37 am

    no problem! 🙂 Always glad to know this helped someone 🙂

    And btw, that requirePermission thingy took me a while as well… Think i noticed an example somewhere and it wasn’t in there as well.

    Reply
  • 4. Eyal  |  February 8, 2008 at 1:20 am

    Can not SVN checkout

    In step 4 “Check out the entire Castle Project repository..” I right clicked on the project folder in the shortcut menu there is a command called SVN checkout…This opens up a window to input the following:
    1.URL of repository: file:///C:\svn\myproject (i created these folders)
    2. Checkout directory: C:\MyProject (content of project)

    clicked ok and this is the error message I got:
    Error: Unable to open repository ‘file:///C:/svn/’myproject’

    Any suggestions?

    cheers
    eyal

    Reply
  • 5. Vincent Hendriks  |  February 8, 2008 at 2:19 am

    Hi Eyal,

    Try using this as the repository:
    http://svn.castleproject.org:8080/svn/castle/trunk/

    you are currently referring to a local drive as the repository but the svn repository is, ofcourse, located online.

    Hope this helps.

    Best Regards,
    Vincent

    Reply
  • 6. Eyal  |  February 8, 2008 at 2:59 am

    hey Vincent,

    is this a public repository and is it safe to use?

    I am assuming that i need to replace this file:///C:\svn\myproject with the following url http://svn.castleproject.org:8080/svn/castle/trunk/

    Thanks

    Eyal

    Reply
  • 7. Eyal  |  February 8, 2008 at 7:42 am

    hi Vincent,

    Please disregard my last post. I managed to check out the castle project which is now located under C:/svn/

    However I’m having trouble with step 7. I executed the commnad line you provided as follows:

    C:/svn> nant -D:common.testrunner.enabled=false -D:assembly.allow-partially-trusted-callers=true

    I am getting an error:

    “The file, directory name or volume label syntax is incorrect.”

    thanks
    eyal

    Reply
  • 8. Vincent Hendriks  |  February 8, 2008 at 9:48 am

    Hey Eyal,

    It’s the trunk version of the castleproject. Public and as safe as opensource is/ can be 🙂 So yes…

    Yes, you are correct, replace file:///C:\svn\myproject with following url http://svn.castleproject.org:8080/svn/castle/trunk/

    Best Regards,
    Vincent

    Reply
  • 9. Vincent Hendriks  |  February 8, 2008 at 2:01 pm

    Sounds to me nant can’t be found. you should add the nant directory to your system variable ‘path’

    Does this help?

    Reply
  • 10. Eyal  |  February 8, 2008 at 8:44 pm

    Hi Vincent ,

    Thanks again for the reply. I managed to check out the castle project smoothly.

    Encountered an Issue:
    I re-referenced all the dlls in my website project from the castle project. Only one problem:
    Castle.Monorail.Framework.dll was not accepted . I kept on getting compile errors. I had no choice but to use the original dll from the .Net framework 2.0

    Do you think that this may be a problem?
    Also can any web host provider that has .Net ver 2.0 with ms sql server 2005 be able to host Monorail app? (if the answer is no can you please recommand one)

    Reply
  • 11. Vincent Hendriks  |  February 8, 2008 at 11:30 pm

    Hi Eyal,

    That sounds strange. I’ll send you the dll’s i built from here. Don’t really know why / how the dll could not get ‘accepted’… What’s the exact message you get?

    About the shared hosting. I don’t believe it should be a problem to host monorail on any shared hosting, although there could always be exceptions.

    By what i have seen so far is most providers (almost all) just run your website under mediumtrust (well, a slightly adjusted mediumtrust level that is). Like i said in my post, i have it running on my brinkster shared hosting account, and they have probably got the same security measures as any other shared host. I believe you’re almost there to get it working… It took me some work as well to figure out what was wrong, but once i found out, everything went very smoothly after that.

    btw, i am not using sql server 2005, but mysql.. I don’t think this will create any problem though..

    Best Regards,
    Vincent

    Reply
  • 12. Eyal  |  February 10, 2008 at 2:25 am

    Hi Vincent,

    Thanks for the reply and files.

    The error I previously got was:
    Error 1 The type or namespace name ‘ExecuteEnum’ could not be found (are you missing a using directive or an assembly reference?)

    With the new files that you sent it fixed the previous error but there is one more left:

    Error 36 ‘SP.Filters.AuthenticationFilter’ does not implement interface member ‘Castle.MonoRail.Framework.IFilter.Perform(Castle.MonoRail.Framework.ExecuteEnum, Castle.MonoRail.Framework.IRailsEngineContext, Castle.MonoRail.Framework.IController)’

    Not sure why. Any idea?

    Thank you and God bless you for your kindness
    Eyal

    Reply
  • 13. Vincent Hendriks  |  February 10, 2008 at 8:10 pm

    No problem. Always glad to help..

    Could be that the monorail version i have (and which i sent to you) is a bit older and they changed an interface…

    Take a look at this code.. Compare this to your own authenticationfilter and hopefully you can see the difference…


    public class AuthenticationFilter : IFilter
    {
    public bool Perform(ExecuteEnum exec, IRailsEngineContext context, IController controller)
    {
    /*
    Authentication logic
    */
    }
    }

    Reply
  • 14. Eyal  |  February 11, 2008 at 4:59 am

    Hey Hendricks,

    Thanks again, your code fixed up the problems.

    Here is my prev code:
    public class AuthenticationFilter : CookieFilter, IFilter
    {
    public new bool Perform(ExecuteEnum exec, IRailsEngineContext context, Controller controller)
    {
    /* code */
    controller.Redirect(“login”, “index”, parameters);
    }
    }

    I ran a simple monorail project (no database) test on my shared host account. There seems to be an issue with permission. I also followed your recommendation on Medium trust level.

    This is the error I got:
    Configuration Error

    Parser Error Message:
    This configuration section cannot be used at this path. This happens when the site administrator has locked access to this section using from an inherited configuration file.

    I tried the following setting but that didnt work either.

    …..

    Source Error:
    Line 19:

    Cheers
    Eyal

    Reply
  • 15. Eyal  |  February 11, 2008 at 5:02 am

    sorry, had to remove tags to demonstrate config file content

    location allowOverride=”true”
    system.web

    /system.web
    /location

    Reply
  • 16. Vincent Hendriks  |  February 19, 2008 at 10:55 pm

    Hi Eyal,

    Sorry it took me a while to reply. Was away and busy with some other things.

    Could you perhaps e-mail me your config file (Ofcourse with any passwords, usernames, ipaddresses, whatever, masked)

    Not sure what the problem is yet. Does it work on your localhost using medium trust?

    Best Regards,
    Vincent

    Reply
  • 17. Eyal  |  February 20, 2008 at 10:37 pm

    Hi Vincent,

    Thanks for the reply. Right now for sake of ease I am testing the monorail default project along with the compiled binaries that you sent me. Works on my machine. However on the site Im getting page not found error.

    The default.aspx attempts to redirect to ~/Home/index.htm but without success. I am not sure why the index.vm is not found within the Views/Home/

    this is my site folder structure:

    MySiteName/ <-root

    sub folder and file list:
    default.aspx
    Web.config
    global.asax
    bin/
    Views/Home/index.vm
    Content/

    Detail of default.aspx file

    protected override void OnLoad(EventArgs e)
    {
    Response.Redirect(“~/Home/index.htm”);
    base.OnLoad(e);
    }

    If you would like I can send you the test prj. I will need your email please.

    Thanks so much

    Eyal

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


November 2007
M T W T F S S
« Oct    
 1234
567891011
12131415161718
19202122232425
2627282930  

Categories


%d bloggers like this: