473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

customErrors and multi-language support

74
Hi there!

I'm developing a VB.NET web application.
If there is a server error the user is directed to a generic error page stating that the system's down and they need to contact us.

(For instance ASP.NET validates input data and screens it for possible <script> tags..if any are found a server error is thrown and the user is directed to this generic page)

This redirection is done through the web.config:
Expand|Select|Wrap|Line Numbers
  1. <customErrors mode="On" defaultRedirect="Errors/CustomError.htm">
My website supports 3 different languages and I was wondering if there was a way to redirect the user to the appropriate htm page according to their language using the web.config file.

Thanks!

-LilOlMe
Jun 11 '07 #1
4 1926
nateraaaa
663 Expert 512MB
Hi there!

I'm developing a VB.NET web application.
If there is a server error the user is directed to a generic error page stating that the system's down and they need to contact us.

(For instance ASP.NET validates input data and screens it for possible <script> tags..if any are found a server error is thrown and the user is directed to this generic page)

This redirection is done through the web.config:
Expand|Select|Wrap|Line Numbers
  1. <customErrors mode="On" defaultRedirect="Errors/CustomError.htm">
My website supports 3 different languages and I was wondering if there was a way to redirect the user to the appropriate htm page according to their language using the web.config file.

Thanks!

-LilOlMe
You could use the CultureInfo object to get the culture from the user's browser. Then you could create a case statement to select the appropriate htm file to display to the user.

Try something like this.
Expand|Select|Wrap|Line Numbers
  1. Imports System.Threading
  2. Imports System.Globalization
  3.  
  4. Thread.CurrentThread.CurrentCulture = new CultureInfo(Request.UserLanguages(0))
  5.  
  6. Select Thread.CurrentThread.CurrentCulture
  7.     Case "Japanese"
  8.       Response.Redirect(CustomErrorsJapanese.htm)
  9.     Case "French"
  10.         Response.Redirect(CustomErrorsFrench.htm)
  11.     Case"German"
  12.       Response.Redirect(CustomErrorsGermanhtm)
  13.     Case Else
  14.         Response.Redirect(CustomErrorsEnglish.htm)    
  15. End Select
You could change the names specified in your Response.Redirect statement to web.config values.

Web.Config
<add key="EnglishUrl" value="http://www.abc.com/CustomErrorsEnglish.htm" />

Expand|Select|Wrap|Line Numbers
  1. Response.Redirect(ConfigurationSettings.AppSettings["EnglishUrl"].ToString())
Hope this helps

Nathan
Jun 11 '07 #2
lilOlMe
74
Thank you for your reply Nathan.
It was very informative.

My problem is that my code never does the Response.Redirect.
Its handled by the Web Server automatically...the web server encounters the error, looks at the web.config file and redirects the user without ever getting to my code.

I can't see how this can help me, unless you know something I don't.

-LilOlMe

You could use the CultureInfo object to get the culture from the user's browser. Then you could create a case statement to select the appropriate htm file to display to the user.

Try something like this.
Expand|Select|Wrap|Line Numbers
  1. Imports System.Threading
  2. Imports System.Globalization
  3.  
  4. Thread.CurrentThread.CurrentCulture = new CultureInfo(Request.UserLanguages(0))
  5.  
  6. Select Thread.CurrentThread.CurrentCulture
  7.     Case "Japanese"
  8.       Response.Redirect(CustomErrorsJapanese.htm)
  9.     Case "French"
  10.         Response.Redirect(CustomErrorsFrench.htm)
  11.     Case"German"
  12.       Response.Redirect(CustomErrorsGermanhtm)
  13.     Case Else
  14.         Response.Redirect(CustomErrorsEnglish.htm)    
  15. End Select
You could change the names specified in your Response.Redirect statement to web.config values.

Web.Config
<add key="EnglishUrl" value="http://www.abc.com/CustomErrorsEnglish.htm" />

Expand|Select|Wrap|Line Numbers
  1. Response.Redirect(ConfigurationSettings.AppSettings["EnglishUrl"].ToString())
Hope this helps

Nathan
Jun 12 '07 #3
nateraaaa
663 Expert 512MB
You can control where the server displays the error using try catch blocks in your code. If you apply error handling to your code you can control what is shown to the user when an error occurs. I recommend debugging to find where an error occurs then placing a try catch block around your code that fails.

try
{
your code here
}
catch(Exception ex)
{
place the code to redirect the user to a specific error page here. Make sure any variable are declared above your try block so that you can access them in your catch block.
}

Nathan
Jun 12 '07 #4
Frinavale
9,735 Expert Mod 8TB
Just add an aspx file to your project and have your web.config redirect you there. The aspx page doesn't even have to show anything at all...just redirects the user to the appropriate html page depending on their language.
Jun 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Samuel | last post by:
A few (not all) of my clients are getting this error with a web thumbnail generator code I wrote ============================= Runtime Error Description: An application error occurred on the...
6
by: John Smith | last post by:
I am trying to implement custom error pages and I get this error message: **************************************************************************** ********...
10
by: Ron Weldy | last post by:
I am working on a website that someone else has set up. They have a web.config file with a customerrors element that points the error handling to a special aspx page. <customErrors...
21
by: nicholas | last post by:
Although in my web.config I have <customErrors mode="off" /> I still get no detailed errors. How comes ? THX This is what I get: Server Error in '/mywebfolder'Application.
1
by: Chumley Walrus | last post by:
I'm having trouble seeing my page when I publish it on my live server. I created a project in VS.net (with MMIT integrated), created a simple index.aspx mobilewebform page , I can see it in my...
6
by: SMG | last post by:
Hi , Sory for incomplete message in last post here is the actual problem.. I am using following code in web.confiig for trapping all the error through out my site.. <customErrors mode="On"...
0
by: dw | last post by:
Hi, all. I've deployed an ASP.NET 1.1 app from my localhost where it works fine to a server on the network, but when accessed from my machine through the Web, it first asks for me to log into the...
5
by: Savas Ates | last post by:
I have a web application It works well in my local folder.. When i upload it to my web server i got To enable the details of this specific error message to be viewable on remote machines,...
0
by: baburk | last post by:
Hi, I want to use the <customErrors> for all <system.web></system.web> If error occure this should be called. I have to write it once not in every <system.web></system.web>. How can I?
15
denny1824
by: denny1824 | last post by:
I have a working website. I copied all the files to a new folder in inetpub/wwwroot and then set that folder as a Virtual Directory in IIS. I try going to that site from the new folder and i am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.