Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Creating hyperlink [a href=”//””>Click Here ]

Creating Hyperlink [a Href=”//””>Click Here ]

There are many different kinds of hyperlinks in HTML. I call the first one static which looks like so :

https://www.domain.com”> Click Here

There is nothing special about this hyperlink. It is very basic, does what it is supposed to do, which is navigating to the address that you provided in href.

Next one, I call it semi-static, which navigates to exactly the page you want, like so:

https://www.domain.com/page.html”>Click Here

Next one, I call it dynamic link, because it has the ability to navigate to the same page but with different options on that page. It depends on the programmer what kind of options he or she want to show:

https://www.domain.com/page.html?param1=123&param2=456&param3=789″>Click Here

The final hyperlink that I wanted to mention is super dyamic, which looks like this:

https://www.domain.com/api/345676/676545/876756799991/11232

The reason that I called it super dynamic is because it uses RESTful architecture and HTTP programming with GET, POST and PUT methods.But that is beyond the scope of this blog post.

Now, lets say, you have already Web Api written in C# and ASP.NET MVC. It has unique controller, and GET, POST and PUT methods in place. Meanwhile, an old website, written in classic ASP, with .asp file extension pages, needs to access our API to get full blown HTML page, and replace old page with newly designed cshtml view, by two ways:

  1. Either by clicking a link on an old ASP page and opening new cshtml view in new tab or window
  2. Or embedding our external cshtml view that our WEB API returns in an IFRAME or object in old classic ASP page.

Now, for either of the two cases, we need HREF. A link. A hyperlink. Besides, classic ASP page has different product numeric IDs, in a drop down list,  that need to be passed to WEB API to get static cshtml view, based on user selection.

So what do you think ? Which kind of hyperlink we will need ?

Obviously not static, and not semi static. We can use dynamic, but since we have WEB API C# in place, we need super dynamic hyperlink.

Now as you know, that passing pure product IDs in a query parameters is not a good idea, because someone very curious might want to try different ID instead of the one that is in our hyperlink, resulting him or her getting product that does not belong to him or her.

So, if your parameters are numerical, like 34523, or 88890889, and not strings, you could do something like this, from inside your classic ASP page:

And in C# WEB API Controller, you will have a GET methos, that looks something like this:

If you notices, 678957 is being used on classic ASP page to multiply the product ID. It is like secret or salt in md5, something similar. And, same number above is used in WEB API c# code to divide the same number to get the original ID.

So building a hyperlink is not so easy it turns out to be. However simple it looks.

Also, first code block has a tag like this: target=myIframeInClassicASPPage“. It means it targets another tag with ID myIframeInClassicASPPage, which we decided to be iFrame. So we want the external cshtml view to load in iFrame, from ASP.NET MVC WEB API C# project in IIS.

Now, in case , and just in case, because I have stumbled across such a thing, your cshtml view does not load in classic ASP, or iFrame displays weird, check your IIS HTTP headers, and explicitly set  X-UA-Compatible property in HTTP Headers section ( You will have to define new HTTP header for your website ) to IE=edge.

This is for it to be cross browser and render properly in IE. I am writing this because I am assuming you are using scripts, bootstrap, font awesome, and all other libraries that need to load with cshtml page as well. So this helps, and works brilliantly !

The end result, is that we have built a super dunamic hyperlink that renders ASP.NET MVC views in classic ASP site page’s iFrame, with all of views scripts, references, etc, using WEB API.

You never know when you will need this !

Thank you.



This post first appeared on Thoughts On Programming, please read the originial post: here

Share the post

Creating hyperlink [a href=”//””>Click Here ]

×

Subscribe to Thoughts On Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×