1

I am trying to use CKFinder in my .NET application. I cannot get any uploads to work, no matter how big or small the file is, or what type of file it is. I have given everyone entire control over the folder that CKFinder should be uploading to (for testing purposes), and it still doesn't work. It is always giving me a "The uploaded file is corrupt" error. Doesn't matter if I try to run it local on my Windows 7 machine, or if I push live on a Windows Server 2012 R2 machine. Please someone help...there is no documentation about this, or I cannot find anything that is relevant to this situation. Thank you in advance!

Kristin C
  • 53
  • 7

2 Answers2

6

It is possible Friendly URLs are responsible for your issue.

If you are using WebForms on .NET Framework 4 (or newer) make sure requests to CKFinder are not modified by WebFormsFriendlyUrlResolver.

You can do this by disabling friendly URLs altogether or by adding your own implementation of WebFormsFriendlyUrlResolver to EnableFriendlyUrls method (usually done in RouteConfig class).

A custom implementation of WebFormsFriendlyUrlResolver may look like this:

public class CKFinderWebFormsFriendlyUrlResolver : WebFormsFriendlyUrlResolver
{
    public override string ConvertToFriendlyUrl(string path)
    {
        if (!string.IsNullOrEmpty(path) && path.ToLower().Contains("/editor/ckfinder"))
        {
            return path;
        }

        return base.ConvertToFriendlyUrl(path);
    }
}
kfazi
  • 617
  • 1
  • 9
  • 21
  • I have set this up, but I don't understand how to call it from my RegisterRoutes method. I originally had routes.EnableFriendlyUrls(settings). Can you help with this? I am using VB.NET. I can't figure out the VB equivalent of this: routes.EnableFriendlyUrls(settings, new Microsoft.AspNet.FriendlyUrls.Resolvers.IFriendlyUrlResolver[] { new MyWebFormsFriendlyUrlResolver() }); – Kristin C Jan 19 '16 at 15:17
4

Figured it out in VB.NET. Here is the code. Hoping it helps someone else someday!

    Public Class MyWebFormsFriendlyUrlResolver
    Inherits WebFormsFriendlyUrlResolver

    Public Sub New()

        MyBase.New()

    End Sub

    Public Overrides Function ConvertToFriendlyUrl(path As String) As String

        If Not String.IsNullOrEmpty(path) And path.ToLower.Contains("/ckfinder") Then

            Return path

        End If

        Return MyBase.ConvertToFriendlyUrl(path)

    End Function

End Class

Public Class RouteConfig

    Public Shared Sub RegisterRoutes(routes As RouteCollection)

        routes.MapPageRoute("P", "P", "~/P.aspx")            

        Dim settings As FriendlyUrlSettings = New FriendlyUrlSettings()
        settings.AutoRedirectMode = RedirectMode.Permanent

        routes.EnableFriendlyUrls(settings, New Microsoft.AspNet.FriendlyUrls.Resolvers.IFriendlyUrlResolver() {New MyWebFormsFriendlyUrlResolver()})

    End Sub

End Class
Kristin C
  • 53
  • 7