I have a website where I wish to display a custom 404 error page when
applicable. I also want to ensure that when a search engine hits a
page that no longer exists, it gets a StatusCode of 404 so it will
eventually remove it from it's index.
Currently to do this, I'm capturing all errors using the
global.asax.cs -Application_Err or proc, setting the approriate
status code and redirecting:
if (CheckForErrorT ype(exc, "System.Web.Htt pException") &&
exc.Message.ToS tring().IndexOf ("does not exist") 0)
{
Response.Status Code = 404;
Response.Redire ct("/pagenotfound.as px", true);
}
When I load Fidder, it tells me that the missing page *is* being
loaded, returning a status code of 302 (object moved) then my friendly
error page is being loaded with the appropriate 404 code which is
useless.
My 404 page inherits from a Master Page, which checks for a Session so
I can't use a Server.Transfer as I get the error:
An exception of type 'System.Web.Htt pException' occurred in
System.Web.dll but was not handled in user code
Additional information: Session state can only be used when
enableSessionSt ate is set to true, either in a configuration file or
in the Page directive. Please also make sure that
System.Web.Sess ionStateModule or a custom session state module is
included in the <configuration> \<system.web>\< httpModulessect ion in
the application configuration.
Alternatively, I've tried using the CustomErrors tag in web.config:
<customErrors mode="RemoteOnl y">
<error statusCode="404 " redirect="/pagenotfound.as px"/>
</customErrors>
Again, using Fiddler, it returns first the 302 status then the 404.
Has anyone else come across this issue and found a decent solution?
TIA 3 6631
You're getting 302 due to the Redirect. Can't you set up a custom 404 page
via IIS admin rather than handling it in your code? That should preserve
the 404 status.
"Dunc" <du**********@g mail.comwrote in message
news:11******** **************@ h2g2000hsg.goog legroups.com...
>I have a website where I wish to display a custom 404 error page when
applicable. I also want to ensure that when a search engine hits a
page that no longer exists, it gets a StatusCode of 404 so it will
eventually remove it from it's index.
Currently to do this, I'm capturing all errors using the
global.asax.cs -Application_Err or proc, setting the approriate
status code and redirecting:
if (CheckForErrorT ype(exc, "System.Web.Htt pException") &&
exc.Message.ToS tring().IndexOf ("does not exist") 0)
{
Response.Status Code = 404;
Response.Redire ct("/pagenotfound.as px", true);
}
When I load Fidder, it tells me that the missing page *is* being
loaded, returning a status code of 302 (object moved) then my friendly
error page is being loaded with the appropriate 404 code which is
useless.
My 404 page inherits from a Master Page, which checks for a Session so
I can't use a Server.Transfer as I get the error:
An exception of type 'System.Web.Htt pException' occurred in
System.Web.dll but was not handled in user code
Additional information: Session state can only be used when
enableSessionSt ate is set to true, either in a configuration file or
in the Page directive. Please also make sure that
System.Web.Sess ionStateModule or a custom session state module is
included in the <configuration> \<system.web>\< httpModulessect ion in
the application configuration.
Alternatively, I've tried using the CustomErrors tag in web.config:
<customErrors mode="RemoteOnl y">
<error statusCode="404 " redirect="/pagenotfound.as px"/>
</customErrors>
Again, using Fiddler, it returns first the 302 status then the 404.
Has anyone else come across this issue and found a decent solution?
TIA
a redirect is a 302. you should do a server transfer rather than a
client redirect.
-- bruce (sqlwork.com)
Dunc wrote:
I have a website where I wish to display a custom 404 error page when
applicable. I also want to ensure that when a search engine hits a
page that no longer exists, it gets a StatusCode of 404 so it will
eventually remove it from it's index.
Currently to do this, I'm capturing all errors using the
global.asax.cs -Application_Err or proc, setting the approriate
status code and redirecting:
if (CheckForErrorT ype(exc, "System.Web.Htt pException") &&
exc.Message.ToS tring().IndexOf ("does not exist") 0)
{
Response.Status Code = 404;
Response.Redire ct("/pagenotfound.as px", true);
}
When I load Fidder, it tells me that the missing page *is* being
loaded, returning a status code of 302 (object moved) then my friendly
error page is being loaded with the appropriate 404 code which is
useless.
My 404 page inherits from a Master Page, which checks for a Session so
I can't use a Server.Transfer as I get the error:
An exception of type 'System.Web.Htt pException' occurred in
System.Web.dll but was not handled in user code
Additional information: Session state can only be used when
enableSessionSt ate is set to true, either in a configuration file or
in the Page directive. Please also make sure that
System.Web.Sess ionStateModule or a custom session state module is
included in the <configuration> \<system.web>\< httpModulessect ion in
the application configuration.
Alternatively, I've tried using the CustomErrors tag in web.config:
<customErrors mode="RemoteOnl y">
<error statusCode="404 " redirect="/pagenotfound.as px"/>
</customErrors>
Again, using Fiddler, it returns first the 302 status then the 404.
Has anyone else come across this issue and found a decent solution?
TIA
Thanks, Bruce. Unfortunately, the 404 page derives from a master
page, which checks session. After some research, it seems the
Application_Err or no longer holds a reference to the current
HttpContext, so redirecting from that causes the 404 page to create
that obscure error about not having session enabled.
D
On 31 May, 16:00, bruce barker <nos...@nospam. comwrote:
a redirect is a 302. you should do a server transfer rather than a
client redirect.
-- bruce (sqlwork.com)
Dunc wrote:
I have a website where I wish to display a custom 404 error page when
applicable. I also want to ensure that when a search engine hits a
page that no longer exists, it gets a StatusCode of 404 so it will
eventually remove it from it's index.
Currently to do this, I'm capturing all errors using the
global.asax.cs -Application_Err or proc, setting the approriate
status code and redirecting:
if (CheckForErrorT ype(exc, "System.Web.Htt pException") &&
exc.Message.ToS tring().IndexOf ("does not exist") 0)
{
Response.Status Code = 404;
Response.Redire ct("/pagenotfound.as px", true);
}
When I load Fidder, it tells me that the missing page *is* being
loaded, returning a status code of 302 (object moved) then my friendly
error page is being loaded with the appropriate 404 code which is
useless.
My 404 page inherits from a Master Page, which checks for a Session so
I can't use a Server.Transfer as I get the error:
An exception of type 'System.Web.Htt pException' occurred in
System.Web.dll but was not handled in user code
Additional information: Session state can only be used when
enableSessionSt ate is set to true, either in a configuration file or
in the Page directive. Please also make sure that
System.Web.Sess ionStateModule or a custom session state module is
included in the <configuration> \<system.web>\< httpModulessect ion in
the application configuration.
Alternatively, I've tried using the CustomErrors tag in web.config:
<customErrors mode="RemoteOnl y">
<error statusCode="404 " redirect="/pagenotfound.as px"/>
</customErrors>
Again, using Fiddler, it returns first the 302 status then the 404.
Has anyone else come across this issue and found a decent solution?
TIA- Hide quoted text -
- Show quoted text -
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: DrUg13 |
last post by:
In java, this seems so easy. You need a new object
Object test = new Object() gives me exactly what I want.
could someone please help me understand the different ways to do the
same thing in C++. I find my self sometimes, trying
Object app = Object();
Object *app = Object();
Object app = new Object();
|
by: Matt Kruse |
last post by:
http://www.JavascriptToolbox.com/bestpractices/
I started writing this up as a guide for some people who were looking for
general tips on how to do things the 'right way' with Javascript. Their code
was littered with document.all and eval, for example, and I wanted to create
a practical list of best practices that they could easily put to use.
The above URL is version 1.0 (draft) that resulted. IMO, it is not a
replacement for the FAQ,...
|
by: |
last post by:
I have an app that retrieves data from an Access database. At the moment I
have the SQL string as a Const in my app. I understand this is not best
practice. I don't want the user to have access to read or modify this string
so I don't want to store it in an INI / Text file or in registery. Can
someone please tell me the best practice for this.
Thanks
Mike
|
by: Fredrik Melin |
last post by:
I have a "Inventory" Object that contains the product and all its fields.
The problem is that I am getting soooooo many functions under main Inventory
class so it becames impossible to initalize a new programmer into this code.
For sample, I have Add_AllowAccess, Add_DisallowAccess, Remove_AllowAccess,
Remove_DisallowAccess, Get_AllowAccess, Get_DisallowAccess (this is only a
sample)
I would really like
|
by: Ren |
last post by:
Hi All,
I'm still rather new at vb.net and would like to know the proper way to access
private varibables in a class. Do I access the variable directly or do I use
the public property?
public class MyClass
private _variableName as integer
public property VariableName as integer
| |
by: Jay Wolfe |
last post by:
Hello,
I'm trying to make sure I use best practices (and hence save myself some
headaches) with the declaration and definition of global variables. Let's
say I have an app with 30 files, including main.cpp I have global
variables that need defining in main.cpp and declaring in all other files
in. The way I've seen it done is to define/declare everything in one header
file (e.g. globalincludes.h) prefaced with the word EXTERN
...
|
by: Ned Balzer |
last post by:
Hi all,
I am pretty new to asp.net; I've done lots of classic asp, but am just
beginning to get my mind wrapped around .net.
What I'd like to do is include some code that tests if a user is logged
in, on each and every page, and redirects the user to a login page if
s/he's not logged in. The login page will also take care of some
standard setup, such as choosing/populating a user profile. I used to
use <!-- #include ... --for this,...
|
by: MikeG |
last post by:
When creating a class library is it wrong or not a 'Best Practice' to
reference a property of an object from within a constructor or method of
that object? I recall being told not to do this but I really don't
understand why. Any insight would be greatly appreciated.
Here is an example of what I mean...
namespace ClassLibrary
{
public class MyClass
{
|
by: kbutterly |
last post by:
All,
I have a menu which contains Category as the master and Product as the
child.
When I click on a Category in the menu, I want one formView control,
fvpc, to show, and then when I click on a Product, I want a different
formview, fvp, to show.
Is it best to have the two forms on separate pages, productView.aspx
|
by: =?Utf-8?B?QW1tZXI=?= |
last post by:
I've read many incomplete opinions about the "Best Practice" for securely
accessing SQL but what I really need to find the "Best Practice" that fits my
applications needs.
Currently (alpha stage) I am Using a .Net DSN-Less SQLConnection method in
my client program (vb.net) and sending uid/pwd across the network. The
client only
calls upon the stored procedures to access the tables in SQL 2005.
This is a semi commercial application...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |