Web Development Blog

Running Lucene.Net under Medium Trust

I'm in the middle of moving a web application from a Full Trust environment to a Medium Trust environment. There was all sorts of things that wouldn't work under Medium Trust as they did under Full Trust. I updated the version of Lucene.Net I was using to Lucene.Net 2.9.2 and of course it wouldn't work out of the box.

This post describes the problem almost exactly.

When I was updating the search index I got the following error.

[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
FileSupport.Sync(FileStream fileStream) +0
Lucene.Net.Store.FSDirectory.Sync(String name) +151
Lucene.Net.Index.SegmentInfos.FinishCommit(Directory dir) +171
Lucene.Net.Index.IndexWriter.Init(Directory d, Analyzer a, Boolean create, Boolean closeDir, IndexDeletionPolicy deletionPolicy, Boolean autoCommit, Int32 maxFieldLength, IndexingChain indexingChain, IndexCommit commit) +257
Lucene.Net.Index.IndexWriter.Init(Directory d, Analyzer a, Boolean closeDir, IndexDeletionPolicy deletionPolicy, Boolean autoCommit, Int32 maxFieldLength, IndexingChain indexingChain, IndexCommit commit) +110
Lucene.Net.Index.IndexWriter..ctor(Directory d, Analyzer a, MaxFieldLength mfl) +369

So I looked at each of the methods in the SupportClass.FileSupport.Sync(FileStream fileStream) method that would throw a SecurityException simply commenting out the code after fileStream.Flush() resolves the security problem.

/// <summary> 
/// Flushes the specified file stream. Ensures that all buffered 
/// data is actually written to the file system. 
/// </summary> 
/// <param name="fileStream">The file stream.</param> 
public static void Sync(System.IO.FileStream fileStream) 
    if (fileStream == null
    { 
        throw new ArgumentNullException("fileStream"); 
    } 
    fileStream.Flush(); 
 
    //if (OS.IsWindows) 
    //{ 
    //    if (!FlushFileBuffers(fileStream.Handle)) 
    //        throw new System.IO.IOException(); 
    //} 
    //else if (OS.IsUnix) 
    //{ 
    //    if (fsync(fileStream.Handle) != IntPtr.Zero) 
    //        throw new System.IO.IOException(); 
    //} 
    //else 
    //{ 
    //    throw new NotImplementedException(); 
    //} 

I recompiled and so far so good I can update the search index under Medium Trust.

 

Using WSE 3.0 in VS 2010 with .NET 4.0

I had a project that used Web Services Enhancements or commonly WSE 3.0 which I recently decided to migrate to .NET 4.0, it had previously been using .NET 3.5. Ina previous post described how to use WSE 3 in Visual Studio 2010

Resize RadSplitter to the size of its content

Working with the Telerik RadSplitter control I had the situation where I had dynamic controls in a panel inside a RadSplitter.

If you are using any sort of tree control or expanding panel you will find the RadSplitter is only resized to the size of the contents when the page first loads and if you change the height of the content you get scroll bars. This is quite undesirable if you are using the left panel for some sort of navigation. I searched for a solution and all information from Telerik indicate this is by design and the control doesn't support this type of behavior.

But it is possible, if you look at the online help you will see they use the splitter control with this exact behavior. Find a page with a little bit on content and expand the tree menu.You will find the RadSplitter controls height is increased and no scroll bars appear. So how come it works here?

I inspected the HTML and styles to see what the differences were with my control. I found the height on each RadPane was set to auto.

So here is the basic setup of the RadSplitter, RadPanelBar and RadPanes. 

<telerik:RadSplitter ID="RadSplitter1" runat="server" CssClass="Splitter" Width="970px" 
    BorderSize="0"
    <telerik:RadPane ID="RadPane1" CssClass="NavigationPanel" runat="server" Width="200px" 
        MaxWidth="200"
        <telerik:RadPanelBar runat="server" ID="RadPanelBar1" Width="200px" CausesValidation="False"
            <Items> 
                <telerik:RadPanelItem runat="server" Text="Show All" Value="showall"
                </telerik:RadPanelItem> 
                <telerik:RadPanelItem Text="Messages" runat="server" Expanded="True" Value="messagesummary"
                    <Items> 
                        <telerik:RadPanelItem Text="Item 1" runat="server"
                        </telerik:RadPanelItem> 
                        <telerik:RadPanelItem Text="Item 2" runat="server"
                        </telerik:RadPanelItem> 
                        <telerik:RadPanelItem Text="Item 3" runat="server"
                        </telerik:RadPanelItem> 
                    </Items> 
                </telerik:RadPanelItem> 
            </Items> 
        </telerik:RadPanelBar> 
    </telerik:RadPane> 
    <telerik:RadSplitBar ID="RadSplitBar1" runat="server" CollapseMode="Forward" EnableResize="False" /> 
    <telerik:RadPane ID="RadPane2" CssClass="ContentPanel" runat="server"
        <asp:Panel ID="Panel1" runat="server"
            <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> 
        </asp:Panel> 
    </telerik:RadPane> 
</telerik:RadSplitter> 

The height is set using JavaScript so the easiest way is to override the height using CSS.

 
.Splitter,.NavigationPanel,.ContentPanel  
    heightauto !important; 

After this CSS addition you will find the splitter will resize to the height of the panels content.