Silverlight Crossdomain file

An example of a clientaccesspolicy.xml

[code:xml]

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

[/code]

An example of a crossdomain.xml

[code:xml]

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

[/code]


For more info you can read this weblog post.

Run website on IIS7 (Vista) in classic mode

If you run your website on IIS7 you can run into the following HTTP errors: 500.22, 500.23

[code:html]

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.

[/code]


If you don't want to change your web.config and still want to run the website on IIS7 you have to change the Application Pool of your Website.

Open IIS, go to your Application Pools, find your Application Pool and double click the Managed PipeLine Mode.

 

Set the Manage Pipeline mode from Integrated to Classic.


Set IIS7 Application Pool Defaults
You can also set the Manage pipeline mode in the Application Pool Defaults. You can do this in IIS7 by clicking on Set Application Pool Defaults.

 

And then change the Managed Pipline Mode to Classic.

 


The other way is changing your web.config to work with IIS7. You can get more information about this by reading this post.

 

Silverlight: Add .xap as MIME Type to IIS

When I tried to run a my Silverlight App on IIS7 I got the following error:

[code:html]

Microsoft JScript runtime error: Sys.InvalidOperationException: InitializeError error #2104 in control 'Xaml1': Could not download the Silverlight application. Check web server settings

[/code]


The solution for this problem is adding .XAP file extension to your IIS MIME Types. The MIME type is application/x-silverlight-app.

If you don't know what a MIME Type is read this post.

CSS: Place vertical text

For a html report I needed the Excel functionality to put text vertical. I didn't know that this was possible but it is.
Put the following code in your page (style in the style section of the head or style sheet of course).

[code:html]

.verticalTextBottomTop {
writing-mode: tb-rl;
filter: flipv fliph;
}
 
.verticalTextTopBottom {
writing-mode: tb-rl;
filter: fliph fliph;
}

<div class="verticalTextBottomTop" style="height: 200px;">Text verticalTextBottomTop</div>
<div class="verticalTextTopBottom" style="height: 200px;">Text verticalTextBottomTop</div>

[/code] 

To prevent word wrap you need to set the height property of the container.

And you get the following output.

IE7

FireFox

 

So as you can see It doesn't work for firefox. I can use it because my project is running under a controlled environment, where all users can only use IE.

Load rss (xml) with Linq to XML on medium trust hosting

For a new project I needed to implement show data from RSS. The site will be hosted on a shared hosting environment with medium trust.

I load the rss with the following code:

[code:c#]

XElement rssFeed = XElement.Load("[REPLACE WITH URL TO RSS]");
var posts = from item in rssFeed.Descendants("item")
                  select new
                  {
                       Title = item.Element("title").Value,
                       Description = item.Element("description").Value
                  };

[/code]


This normally works fine for me… But apparently not with medium trust :-(! I got the following error.

[code:c#]

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

[/code]


After reading a bit and playing with the web.config setting <TRUST /> I found the solution. The solution is putting a ".*" in the originUrl parameter of the trust node.

[code:c#]

<trust level="Medium" originUrl=".*" />

[/code]


So an easy solution for a annoying problem what took me to much time. So I hope this post will help somebody out there 🙂