[RESOLVED] How to redirect to another project's localhsot in ASP.NET

I have the following part of the code in one of my ASP.NET Web Forms application. The point is that in my solution, I have another ASP.NET Web Forms application, but of course with different `localhost port`. The thing is that, I want to redirect actions taken by the code below, to my first projects `localhost`. Meaning, it should read the image thumbs from my first projects `localhost`, when someone clicks on the name of the book, it should redirect it to my first `localhost`, where there is more information about book, and most importantly, if someone clicks Add to Cart, I want it to be placed in my first projects cart. So, I just want to redirect those actions to my first project's `localhost`. Here is the `localhost` of my first project: `http://localhost:53417/`

I guess I need to somehow change the parts regarding `href` or change something in `MapPageRoute`, but don't know how. If someone can give me some code help, I would be glad. Please note that below code is inside a ListView.

<ItemTemplate>
                                    <td id="Td2" runat="server">
                                        <table>
                                            <tr>
                                                <td>&nbsp;</td>
                                                <td>
                                                    <a href="<%#: GetRouteUrl("BookByNameRoute", new {bookName = Item.BookName}) %>">
                                                        <image src='/Catalog/Images/Thumbs/<%#:Item.ImagePath%>'
                                                            width="75" height="100" border="1"/>
                                                    </a>
                                                </td>
                                                <td>
                                                    <a href="<%#: GetRouteUrl("BookByNameRoute", new {bookName = Item.BookName}) %>">
                                                        <%#:Item.BookName%>
                                                    </a>
                                                    <br />
                                                    <span class="BookPrice">
                                                        <b>Price: </b><%#:String.Format("{0:c}", Item.UnitPrice)%>
                                                    </span>
                                                    <br />
                                                    <a href="/AddToCart.aspx?bookID=<%#:Item.BookID %>">
                                                    <span class="BookListItem">
                                                        <b>Add To Cart<b>
                                                    </span>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </ItemTemplate>

Global.asax.cs:

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.RegisterOpenAuth();
        RouteConfig.RegisterRoutes(RouteTable.Routes);

        RegisterRoutes(RouteTable.Routes);
    }

    void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute(
            "HomeRoute",
            "Home",
            "~/Default.aspx"
        );
        routes.MapPageRoute(
            "AboutRoute",
            "About",
            "~/About.aspx"
        );
        routes.MapPageRoute(
            "ContactRoute",
            "Contact",
            "~/Contact.aspx"
        );
        routes.MapPageRoute(
            "BookByNameRoute",
            "Book/{bookName}",
            "~/Catalog.aspx"
        );
    }


GetRouteUrl returns URL like /Book/SomeName. So, to make it as http://localhost/Book/SomeName add "http://localhost"

<a href="http://localhost<%#: GetRouteUrl("BookByNameRoute", new {bookName = Item.BookName}) %>">

To redirect AddToCart set correct url

<a href="http://localhost/AddToCart.aspx?bookID=<%#:Item.BookID %>">

I hope you understand that this will work only on the test server and need to be modified when going on production.

Thanks, it worked just fine.

thoughts on "[RESOLVED] How to redirect to another project's localhsot in ASP.NET "

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>