Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Throw a 404 status code and then redirect to 404 page from API View modes: 
User avatar
Member
Member
joeh42 - 2/9/2012 3:58:58 PM
   
Throw a 404 status code and then redirect to 404 page from API
If someone enters an invalid query string parameter to my web part, I want to respond with a 404 and redirect them my 404 page.

How can I do so?

I setup my web.config as:


<customErrors defaultRedirect="~/Special-Pages/Server-error.aspx" mode="On">
<error statusCode="404" redirect="~/CMSMessages/PageNotFound.aspx"/>
</customErrors>


When I use the API call RequestHelper.Respond404();, the page responds with a 404 status but does not send a redirect.

throw new HttpException(404, "Forum post not found"); sends the page to the ~/CMSMessages/PageNotFound.aspx?aspxerrorpath=/CMSPages/PortalTemplate.aspx: Page /CMSPages/PortalTemplate.aspx was not found.

How can I do so?

Thanks!
Joe Hoppe

User avatar
Member
Member
joeh42 - 2/16/2012 2:04:28 PM
   
RE:Throw a 404 status code and then redirect to 404 page from API
Anyone?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 2/19/2012 1:45:39 AM
   
RE:Throw a 404 status code and then redirect to 404 page from API
Hi,

What are your Page not found settings set in Site Manager -> Settings -> select your site from the drop down -> Content -> Page not found URL?

Are you getting a proper 404 page when you type non existing page to the URL?

Best regards,
Juraj Ondrus

User avatar
Member
Member
joeh42 - 2/21/2012 9:05:35 AM
   
RE:Throw a 404 status code and then redirect to 404 page from API
My page not found setting is set to ~/Special-Pages/Page-not-Found.aspx in the global settings. The site level settings are set to inherit.

If I type a bogus URL into the address bar, i.e. mysite.com/asdf, I am redirected to that page.

Suggestions?


User avatar
Kentico Support
Kentico Support
kentico_jurajo - 2/22/2012 2:59:06 AM
   
RE:Throw a 404 status code and then redirect to 404 page from API
Hi,

In the web.config custom errors configuration, could you please try to add this attribute to the customErrors element:

redirectMode="ResponseRewrite"

This should ensure that the original URL will be displayed whereas the 404 error will be returned.

Best regards,
Juraj Ondrus