How to Use ibatis/Nhibernate in medium Trust/partial trust environments like mosso

Source: Internet
Author: User
Tags shared hosting
Http://programcsharp.com/blog/archive/2009/08/19/ibatis-nhibernate-mosso-medium-trust-partial-trust-environments.aspx

Using shared hosting providers (in this case mosso) run your asp. net Applications in a medium trust or modified medium trust environment to reduce security risks. this causes issues with certain techniques and components that require permissions removed by medium trust.

One of the biggest issues other than the actual restriction of permissions is the restriction of partially trusted assemblies calling fully trusted code. by default, if an assembly is strong named, partially trusted assemblies (I. e. the application assemblies in your app running under medium/partial trust) Can't call it. this hits implements open source components such as ibatis and nhib.pdf. the workaround to this is to add the allowpartiallytrustedcallers Assembly level attribute. this will mark the Assembly as safe for calling by partially trusted assemblies.

Here is an example of how to modify ibatis to support this:

    1. Download the ibatis source from the ibatis Website: http://ibatis.apache.org/dotnet.cgi
    2. Extract the source. Zip to a folder
    3. Open the ibatisnet.2005.sln solution in vs. net
    4. For each project in the solution, open it's assemblyinfo. CS File
      1. Add this using statement at the top of the file: "using system. Security ;"
      2. Add this attribute at the bottom of the file: "[Assembly: allowpartiallytrustedcallers]"
    5. Right click on the solution and select "Configuration Manager ..."
    6. In the "Active solution configuration" dropdown, select release
    7. Uncheck all of the test projects
    8. Click OK
    9. Build the solution

Or you can download the compiled assemblies: iBatis-PartialTrust.zip

Enabling nhibure for medium/partial trust is a similar procedure. If there is enough demand I will present steps and compiled assemblies for it as well.

As for the permission restrictions, most shared hosting providers don't actually run in medium trust as this restricts used useful things such as reflection etc. one example I 've run into recently is mosso's modified medium trust. they take medium Trust, which consists of the following denied permission restrictions:

    • Call unmanaged code.
    • Call Serviced components.
    • Write to the event log.
    • Access Microsoft Message Queuing queues.
    • Access ODBC, oledb, or Oracle data sources.
    • Access files outside the application directory.
    • Access the registry.
    • Make network or Web Service cballs (using the system. net. httpwebrequest class, for example ).

And then mosso adds back in the following allowed permission to come up with "modified medium Trust ":

    • Webpermission unrestricted = "true"
    • Oledbpermission unrestricted = "true"
    • Odbcpermission unrestricted = "true"
    • Socketpermission unrestricted = "true"
    • Configurationpermission unrestricted = "true"
    • Reflectionpermission unrestricted = "true"

This is still rather limiting, but at least you can get most things done as long as you can call into the necessary assemblies without getting exceptions as discussed in the workaround section above.

Wednesday, August 19,200 9 pm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.