Developer forum

Forum » Development » Razor: try-catch in IE

Razor: try-catch in IE

Denys Ubizskyy
Reply

Hi.

 

I've experienced a problem. When I try to execute this piece of code via Razor where 1234 is ID of the defunct page, my IE browser crashes:

​try {
   var key = "UK";
   var value = SearchEngineFriendlyURLs.GetFriendlyUrl(1234);
   pages.Add(key,value);
}
catch(Exception e) {
   continue;
}

But other browsers show the page correctly.(???) I think this is because of the method GetFriendlyUrl(int pageID) which crashes during executing.

Can you suggest some solution?

 

Thank you in advance!


Replies

 
Nicolai Høeg Pedersen
Reply

Do not use IE? Server side code is the same weather it is IE or another browser, so I think it is the resulting broken HTML from your layout which is causing the issue.

And you should NEVER lookup friendly URLs in Dynamicweb. Simply print out Default.aspx?ID=1234 and DW will handle the rest.

 

 
Denys Ubizskyy
Reply

I need to insert into my HTML the alternative link by page ID

<link rel='alternate' hreflang='en-au' href='http://www.example.com.au/some-directory/some-page.aspx'>

so

<link rel='alternate' hreflang='en-au' href='http://www.example.com.au/Default.aspx?ID=1234'>

is not what I need.

 

 
Nicolai Høeg Pedersen
Reply

Oh.

Yes, then you need that method. Otherwise DW will 301 the ID=1234 to the right page.

 
Denys Ubizskyy
Reply

Now I will explain what I mean. The error is not in HTML.

For example, lets take this code and look at the results in Chrome and IE (link): 

@using Dynamicweb.Frontend;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <title>Test</title>
</head>
@{
  int id = 99999;
  string url = "";
  try {
      url = SearchEngineFriendlyURLs.GetFriendlyUrl(id);
  }
  catch(Exception e) {
      url = "unknown page";
  }
}  
<body>  
  <div>
    <h1>This is testing page!</h1>
    <p>@url</p>   
  </div>
  <div class="dwcontent" id="content" title="Main content"></div>
  
</body>
</html>

 

 
Nicolai Høeg Pedersen
Reply

Well, it is the same response to both browsers. So it is an IE thing - it does not crash my IE, but shows gibberish.

Try this code to find the URL instead:

Frontend.Page p = Frontend.Page.FindPage(pageID);
if ((p != null)) {
 return p.Value("PagePathUrl").ToString();
}
 
Denys Ubizskyy
Reply

Thank you Nicolai! That works.
 

 

You must be logged in to post in the forum