Developer forum

Forum » Development » Building a working 404 system for websites without primary domain

Building a working 404 system for websites without primary domain

Martin Nielsen
Reply

Hi devs,

I'm trying to build a 404 setup that works for solutions that do not use a primary domains.

My solution has 10 languages that all have to work on the same domain, eg.

 

domain.com/dk
domain.com/uk
domain.com/de
...

 

Since i'd like to have a seperate 404 page for each language, i'm trying to build a module that can sniff out the area qualifier (/dk, /uk, /de) part of the requested URL and based on that find the correct 404 page to show.

 

The highlighted part of the URL below i can use to find the area and hence the 404 page :

domain.com/dk/segment1/segment1/page-doesnt-exist.html  (this only work if there is a area qualifier. so i'd have to make a fallback rutine)

 

I've made this logic, but my problem now, is that i'd like to stay on the current URL, give a 404 status code, but show the output that would otherwise be shows if i visited the 404 page normally.

 

I've tried using the Dynamicweb.Notifications.Standard.Page.NotFound since this made the most sence, but i don't have access to a pageview here, so i cant replace the output, can i?

 

I'm hoping someone has built this before, and can help me out :)

 

// Martin

 

 

 

 


Replies

 
Martin Nielsen
Reply

Is everyone at Dynamicweb busy with the upcoming TechConf?

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Martin

Yes we are :-).
 

Using Dynamicweb.Notifications.Standard.Page.NotFound is the way to go. And you will not have a pageview in that situation because the page was not found, so a page does not exist.

But do like this:

'find your page id based on your logic
Dim pv As Frontend.PageView = Frontend.PageView.GetPageviewByPageID(12)
pv.Redirect = False
pv.Meta.Add("basehref", "http://" & HttpContext.Current.Request.ServerVariables("SERVER_NAME") & "/")
HttpContext.Current.Response.Write(pv.Output)
HttpContext.Current.Response.Status = "404 Not Found"
HttpContext.Current.Response.StatusCode = 404
HttpContext.Current.Response.StatusDescription = "Not Found"
HttpContext.Current.Response.End()

 

Votes for this answer: 1
 
Martin Nielsen
Reply

Hi Nicolai,

Works like a charm :-)

Thank you for taking time out of your, i imagine, very busy schedule.

I'm looking forward to the TechConf. Hoping to get a few geeky days in Aarhus.

// Martin

 

You must be logged in to post in the forum