Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Problem with ashxProblem with ashx
Previous
 
Next
New Post
4/18/2009 6:32 PM
 

Hello,

I have found a problem with ashx files.
Here are steps to reproduce the problem :

1. Install DotNetNuke 5.0.1
2. Add a new page "Contact"
3. Go to the "Home" page and redirect the "Home" page to "Contact"
4. If you look at your database, the table "Tabs", row "Home", you should have in the column "Url" the Id of the "Contact" page
5. With this configuration, all .ashx files doesn't work.
6. Put a HelloWorld.ashx file on the root of the website :

File HelloWorld.ashx
------
<%@ WebHandler language="VB" class="InfoPAK.Test.HelloWorld" %>
Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2d
Imports System.Drawing.Imaging
Imports System.Web
Imports Microsoft.VisualBasic
Namespace InfoPAK.Test
    Public Class HelloWorld : Implements IHttpHandler
#Region " Properties "
    Public ReadOnly Property IsReusable As Boolean Implements IHttpHandler.IsReusable
        Get
            Return True
        End Get
    End Property
#End Region
#Region " Event Handlers "
 Public Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
        context.Response.Write("Hello World!")
    End Sub
#End Region
    End Class
End Namespace
-------
 

If you try to access to HelloWorld.ashx, you will be redirected to "Contact" page.
The problem is in DotNetNuke.HttpModules.UrlRewrite.UrlRewriteModule.vb on the line :

If PortalId <> -1 Then
' load the PortalSettings into current context
Dim _portalSettings As PortalSettings = New PortalSettings(TabId, objPortalAliasInfo)
app.Context.Items.Add(
"PortalSettings", _portalSettings)
' manage page URL redirects - that reach here because they bypass the built-in navigation
' ie Spiders, saved favorites, hand-crafted urls etc
If _portalSettings.ActiveTab.Url <> "" And Request.QueryString("ctl") Is Nothing Then
'Target Url
Dim redirectUrl As String = _portalSettings.ActiveTab.FullUrl
If _portalSettings.ActiveTab.PermanentRedirect Then
'Permanently Redirect
Response.StatusCode = 301
Response.AppendHeader(
"Location", redirectUrl)
Else
'Normal Redirect
Response.Redirect(redirectUrl, True)
End If

 TabId is -1 and the first Tab of the collection will be returned with the Url property that point to the "Contact" page.
I suggest to add an exception ashx at the beginning of the function OnBeginRequest :

            If Request.Url.LocalPath.ToLower.EndsWith("scriptresource.axd") _
                    OrElse Request.Url.LocalPath.ToLower.EndsWith("webresource.axd") _
                    OrElse Request.Url.LocalPath.ToLower.EndsWith("gif") _
                    OrElse Request.Url.LocalPath.ToLower.EndsWith("jpg") _
                    OrElse Request.Url.LocalPath.ToLower.EndsWith("css") _
                    OrElse Request.Url.LocalPath.ToLower.EndsWith("js") _
                    OrElse Request.Url.LocalPath.ToLower.EndsWith("ashx") Then
                Exit Sub
            End If

Hope, that this issue will be corrected in the next release :-)

 
New Post
4/18/2009 7:56 PM
 

With the solution above the ashx files works, but aspx files not.
Here is a cleaner solution :

            If PortalId <> -1 Then

                ' load the PortalSettings into current context
                Dim _portalSettings As PortalSettings = New PortalSettings(TabId, objPortalAliasInfo)
                app.Context.Items.Add("PortalSettings", _portalSettings)

                ' manage secure connections
                If Request.Url.AbsolutePath.ToLower.EndsWith(".aspx") Then
                    ' request is for a standard page
                    strURL = ""
                    ' if SSL is enabled
                    If _portalSettings.SSLEnabled Then
                        ' if page is secure and connection is not secure
                        If _portalSettings.ActiveTab.IsSecure = True And Request.IsSecureConnection = False Then
                            ' switch to secure connection
                            strURL = requestedPath.Replace("http://", "https://")
                            strURL = formatDomain(strURL, _portalSettings.STDURL, _portalSettings.SSLURL)
                        End If
                    End If
                    ' if SSL is enforced
                    If _portalSettings.SSLEnforced Then
                        ' if page is not secure and connection is secure
                        If _portalSettings.ActiveTab.IsSecure = False And Request.IsSecureConnection = True Then
                            ' check if connection has already been forced to secure
                            If Request.QueryString("ssl") Is Nothing Then
                                ' switch to unsecure connection
                                strURL = requestedPath.Replace("https://", "http://")
                                strURL = formatDomain(strURL, _portalSettings.SSLURL, _portalSettings.STDURL)
                            End If
                        End If
                    End If
                    ' if a protocol switch is necessary
                    If strURL <> "" Then
                        If strURL.ToLower.StartsWith("https://") Then
                            ' redirect to secure connection
                            Response.Redirect(strURL, True)
                        Else ' when switching to an unsecure page, use a clientside redirector to avoid the browser security warning
                            Response.Clear()
                            ' add a refresh header to the response
                            Response.AddHeader("Refresh", "0;URL=" & strURL)
                            ' add the clientside javascript redirection script
                            Response.Write("<html><head><title></title>")
                            Response.Write("<!-- <script language=""javascript"">window.location.replace(""" & strURL & """)</script> -->")
                            Response.Write("</head><body></body></html>")
                            ' send the response
                            Response.End()
                        End If
                    End If
                End If

                ' manage page URL redirects - that reach here because they bypass the built-in navigation
                ' ie Spiders, saved favorites, hand-crafted urls etc
                If _portalSettings.ActiveTab.Url <> "" And Request.QueryString("ctl") Is Nothing Then

                    'check if the requested file exists
                    If Not System.IO.File.Exists(Server.MapPath(Request.Url.LocalPath)) Then

                        'Target Url
                        Dim redirectUrl As String = _portalSettings.ActiveTab.FullUrl

                        If _portalSettings.ActiveTab.PermanentRedirect Then
                            'Permanently Redirect
                            Response.StatusCode = 301
                            Response.AppendHeader("Location", redirectUrl)
                        Else
                            'Normal Redirect
                            Response.Redirect(redirectUrl, True)
                        End If

                    End If

                End If

I just invert the .aspx and url redirect blocks, with a supplementary check of the file on the server in the redirect url block.
 

 
New Post
4/19/2009 12:04 AM
 

Silverlight FileUploader (http://dnnsilverlight.adefwebserver.com/Silverlight20/SilverlightFileUploader/tabid/73/Default.aspx) uses an .ashx file and the last time I tested it, it worked in DNN5 without any modifications. However it is in the "/DesktopModules/SilverlightFileUploader" directory not the DNN root.



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
4/19/2009 6:15 AM
 

Hello Michael,

For me too, it works when the first page "Home" is not redirected. Try to redirect the first page to another page (table Tabs, column Url).
I use the SimpleGallery module and it's the same configuration as Silverlight File Uploader. For viewing pictures SimpleGallery use ImageHandler.ashx and it's located in DesktopModules/SimpleGallery/ImageHandler.ashx. Without "Home" page redirection, the module works perfectly, but when you redirect the "Home" page, it stops working.

It's simple to test, just add a redirection to your "Home" page or the first page of your website. Remember that the tabid is -1 when the page-tab is not found and the first element is selected in the collection of tabs and it's the "Home" page.

 
New Post
4/19/2009 6:39 AM
 

 please log issue and your solution into the public issue tracker (2nd from top) at support.dotnetnuke.com.


Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Problem with ashxProblem with ashx


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out