Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8346563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:03:46+00:00 2026-06-09T07:03:46+00:00

I implemented URL routing in my multilingual project my link looks like this 1>

  • 0

I implemented URL routing in my multilingual project my link looks like this

1> with URL Routing http://www.example.com/Default.aspx?page=1&Language=en-US
2> With URL Routing http://www.example.com/1/en-US

3> and 3rd scenario can be http://www.example.com/Default.aspx or http://www.example.com

I can check if query string is null or RouteData value is null

but in 3 case i have to detect the browser default language & redirect them according.

if i write my code as

if (!string.IsNullOrEmpty(Request["Language"]))
  {
   lang = Request["Language"].ToString();
  }
if (!string.IsNullOrEmpty(HttpContext.Current.Request.RequestContext.RouteData.Values["Language"].ToString()))
 {
    lang = HttpContext.Current.Request.RequestContext.RouteData.Values["Language"].ToString();
 }

It generate following error if Route Data is null Object reference not set to an instance of an object

How can i make this statement handle null exception with out try catch block

HttpContext.Current.Request.RequestContext.RouteData.Values["Language"].ToString();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:03:48+00:00Added an answer on June 9, 2026 at 7:03 am

    You can use RouteValueDictionary.ContainsKey instead of string.IsNullOrEmpty().

    What’s happening at the moment, is your string.IsNullOrEmpty() requires a string, so, naturally you’re calling .ToString() on the RouteData. However, you’re calling .ToString() on a null object, which is causing your error. I would re-write it like this:

    if (HttpContext.Current.Request.RequestContext.RouteData.Values.ContainsKey("Language")) {
        // .. process it here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the code I'm putting on my website: <iframe src=http://www.facebook.com/plugins/like.php?app_id=5766773068&amp;href&amp;send=false&amp;layout=standard&amp;width=47&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=35 scrolling=no frameborder=0 style=border:none;
In my application, I implemented Google signout using jsapi. I used the url https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=xxxxxx
so my url is currently: http://www.mywebsite.com/search.php?keyword=stack+overflow I'm wanting to have it accessible as: http://www.mywebsite.com/?s=stack+overflow
I've implemented url routing under asp.net 3.5 with the following code: public IHttpHandler GetHttpHandler(RequestContext
I've implemented url routing with the following rule: string virtualPath = ~/ + requestContext.RouteData.Values[page].ToString();
I am looking to implement a similar url as stackoverflow to an eshop: http://wwww.shop.com/products/123123/product-name
I'd like to implement the asp.net 3.5 url routing functionality to take in links
I have an ASP.NET 4.0 application that implements URL routing. This gives me page
I have implemented my own IRouteHandler for URL routing. For files without extension it
I'm currently using URL Rewriting, but I recently stumbled upon this link on Rerouting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.