Developer forum
E-mail notifications
301 redirects
But it appears that when a page doesnt exist, my subscriber isnt invoked.
Any idea what causes this and how to handle it?
Sincerely Sune Fengel
Replies
What notification are you using?
And what do you wan't to accomplish - then I might find another solution.
Be aware, that Dynamicweb with 7.0 changed all 302 redirects from pageview object to be 301.
I have a massive loop that should redirect a non existing url to a new specific url (vi moved the site from a php solution to a DW solution).
something like:
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains(
I use the Dynamicweb.Notifications.Standard.Page.Loaded
It might not work, but alternatively you should add you piece of code to Application_OnPreRequestHandlerExecute in Global.asax
How do I add my code to the global Asax file?
I can see that it inherits from Dynamicweb.Admin.Global.
Do I just write my snippet in the .asax file itself?
How do I compile my own global.asax.cs file into the project?
I've just mailed you a global.asax and global.asax.cs you can compile into your project.
I didnt have a custom project, just a lot of modules.
But I created a CustomModules.dll and changed the application tag to
<%@ Application Codebehind="Global.asax.cs" Inherits="CustomModules.Global" %>.
I managed to write out a testline when I go to the root of the site.
But when I enter a wrong url like: /version3/destinationer/kenya_med_undersider/kenya-hoteller.php it doesnt reach the Application_OnPreRequestHandlerExecute event.
So the global ajax thing is working, but alas I'm back to square 1 :(.
Any other suggestions?
- Sune
requests for .php files are not routed by default into the .NET isapi - Dynamicweb handles this by using its own 404 handler (/Admin/Public/404.aspx) which is setup in IIS manager.
How to set that up can be found in installation guide - also sending you a screen dump of the setup of the live site.
You should be able to catch this 404 from global.asax...
Try this bit of code - and work from there...
Sub Application_OnPreRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs)
If HttpContext.Current.Request.Url.ToString().ToLower().Contains(".php") Then
Dim url As String = HttpContext.Current.Request.Url.ToString().ToLower()
'For test:
'HttpContext.Current.Response.Write(url)
'HttpContext.Current.Response.End()
'Entering http://basicmodules.local.dynamicweb.dk/DoesNotExist.php in the browser
'Give me something like this:
'http://basicmodules.local.dynamicweb.dk/admin/public/404.aspx?404;http://basicmodules.local.dynamicweb.dk:80/doesnotexist.php
'To handle:
If url.Contains("doesnotexist.php") Then
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.Status = "301 Moved Permanently"
HttpContext.Current.Response.StatusCode = 301
HttpContext.Current.Response.StatusDescription = "Moved Permanently"
HttpContext.Current.Response.AddHeader("Location", "DoesExist.aspx")
HttpContext.Current.Response.AddHeader("X-CUSTOM-MSG", "From my own 404 handler bit") 'This header can be seen with Fiddler tool - for debugging
End If
End If
GlobalAsax.Application_OnPreRequestHandlerExecute(sender, e)
End Sub
You can use the direct paths module from modules tab (Dynamicweb.NET) or management center (Dynamicweb 7).
If you do not want to type that in by hand - fill the table containing the information. Think it is pretty self explaining.
UrlPathID [Integer] | UrlPathPath [String] | UrlPathRedirect [String] | UrlPathStatus [Integer] | UrlPathCreated [Date] | UrlPathUpdated [Date] | UrlPathActive [Boolean] |
1 | welcome.php | welcome.aspx | 301 | 2/21/2008 10:36:16 AM | 2/21/2008 10:36:16 AM | True |
2 | en | Default.aspx?ID=58 | 301 | 4/4/2008 11:14:06 AM | 4/4/2008 11:15:30 AM | True |
What this does is redirecting "UrlPathPath" to "UrlPathRedirect" using "UrlPathStatus" as status code. UrlPathStatus can be 301, 302 or 200.
You can easily add records like this:
Dim up As New Dynamicweb.UrlPath.Path
up.UrlPathPath = "someoldlink.php"
up.UrlPathRedirect = "NewLocation.aspx"
up.UrlPathStatus = 301
up.Save()
Regarding your previous post I did the following test based on the code you sent me:
public void Application_OnPreRequestHandlerExecute(object sender, EventArgs e)
{
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains(".php"))
{
string url = HttpContext.Current.Request.Url.ToString().ToLower();
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("version3/hovedmenu/rejsemaal.php"))
{
Base.w("!Exist");
}
}
GlobalAsax.Application_OnPreRequestHandlerExecute(sender, e);
}
But still it doesnt appear to raise this event.
Ill just give it a test with the direct urlpath and check with my boss if it is something we should continue with instead.
- Sune
The 404 handler has already taken over, and will display something - depending on how you set up 404 in Control Panel.
To see it work you would have to end the request:
Base.we("Found and stopping request")
I tested and it worked so it looks like were gonna go with the Direct paths module on this one.
thanks for your help anyway :).
- Sune
You must be logged in to post in the forum