Question : ASP.NET: URLs with apostrophes throwing error on server but not in dev environment

I have an ASP.NET app, developed in VS2008, that's running on IIS 6. It accesses a SQL Server 2005 database and generates URLs based on data in a particular column. For example, if the column contains the text "Some Sample Text", the generated URL would be:

http://MyApp/default.aspx?name=Some+Sample+Text

The app works fine, except for one weird error. If the string from the source column includes an apostrophe -- say, "Here's Some Sample Text" -- it generates a URL formatted like so:

http://MyApp/default.aspx?name=Here%3bs+Some+Sample+Text

This works perfectly in the dev environment and debugger, but when I publish the site to the server, any generated URL that includes an apostrophe are throwing a runtime error. The error itself is below, and the definition of the "Breadcrumbs" method it references is attached. I'd be grateful for whatever help you can offer. If you need any more information about the app, just ask. Thanks.

**************************************************

There is no row at position 0.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: There is no row at position 0.

Source Error:

Line 105:        <asp:View runat="server" ID="ViewDescription">
Line 106:            <p></p>
Line 107:            <div class="style4" style="font-size: 10pt; font-family: Arial"><%= Breadcrumbs() %></div>
Line 108:            <div class="style4">
Line 109:                <br />
 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
public string Breadcrumbs()
        {
            if (Request.QueryString["category"] == null && Request.QueryString["name"] == null)
                return string.Empty;
            else if (Session["category"] != null && Session["name"] == null)
                return string.Format("<a href='default.aspx'>Library</a> &gt; <b>{0}</b>", Session["category"]);
            else if (Session["category"] != null && Session["name"] != null)
                return BreadcrumbHelper(Session["category"], ParseQueryName(Session["name"]));
            else if (Session["category"] == null && Session["name"] != null)
                //if directly
                return BreadcrumbHelper(LibraryModuleHelper.Category(Session["name"].ToString()), ParseQueryName(Session["name"]));

            return string.Empty;
        }

Answer : ASP.NET: URLs with apostrophes throwing error on server but not in dev environment

Are you using javascript in you code,
If so, the ' is interpreted  as end of string and it is breaking your code, you need to replace it, check:
http://www.devx.com/tips/Tip/13618

Note: If you are not using js, that does not mean the your internal code is not generating js (have a look in IE at the source of your page)
Random Solutions  
 
programming4us programming4us