Issue regarding Address bar URL

Add-in Express™ Support Service
That's what is more important than anything else

Issue regarding Address bar URL
 
Rafiqul Islam




Posts: 4
Joined: 2011-12-24
I m creating a toolbar to show customise content in the page if user type wrong URL in the address bar, for example www.add-in-express, instead of www.add-in-express.com.
I want to create a page dynamically & not to change the url.
Also, in IE it goes to google/bing site (default search provider). How can I stop this to happen.
i wrote the code in BeforeNavigate2 function.

Thanks
Rafiq
Posted 27 Dec, 2011 02:44:25 Top
Sergey Grischenko


Add-in Express team


Posts: 7224
Joined: 2004-07-05
Hi Rafiq,

You can change the default search provider in the 'Manage Add-ons' dialog in IE.
To redirect the user to another Url (or a local web page), you can use the BeforeNavigate2 event.

I want to create a page dynamically & not to change the url.

IE doesn't provide such a possibility.
Posted 27 Dec, 2011 07:13:42 Top
Rafiqul Islam




Posts: 4
Joined: 2011-12-24
Thanks Sergey.
Is there any way to bypass/stop default search provider from code?
If bing is default search provider and if I type add-in-express, it goes to bing first then
shows my custom page. So there is a flickering issue.

Also can I show www.add-in-experss/test.html, considering test.html is in local pc already?
Do you have any sample code or guidelines that I can follow for both the cases?
Posted 27 Dec, 2011 08:43:29 Top
Sergey Grischenko


Add-in Express team


Posts: 7224
Joined: 2004-07-05
Hi Rafiqul,

Is there any way to bypass/stop default search provider from code?

I am not aware of such a possibility. In any case it will not help you because IE inserts 'http://' prefix into any url regardless whether it is valid or not. So, there is not any chance to check if the user enters a valid address. I tested it using the code below:

private bool IsWebUrl(string path)
{
Uri result = null;

if (!Uri.TryCreate(path, UriKind.Absolute, out result) || (result == null))
return false;

if (!string.Equals(result.Scheme, Uri.UriSchemeHttp, StringComparison.InvariantCultureIgnoreCase) && !string.Equals(result.Scheme, Uri.UriSchemeHttps, StringComparison.InvariantCultureIgnoreCase))
return false;

return true;
}

private void IEModule_BeforeNavigate2(ADXIEBeforeNavigate2EventArgs e)
{
string url = (string)e.Url;
if ((!String.IsNullOrEmpty(url)) && (url.ToLowerInvariant() != "about:blank"))
{
if (!IsWebUrl(url))
{
e.Cancel = true;
this.IEApp.Stop();

object dummy = null;
this.IEApp.Navigate("//www.add-in-express.com", ref dummy, ref dummy, ref dummy, ref dummy);
}
}
}

However, you can use the code below to check if the url exists.

public bool UrlExists(string url)
{
WebRequest request = null;
WebResponse response = null;

bool flag;

try
{
request = WebRequest.Create(url);
request.Method = "HEAD";
response = request.GetResponse();
flag = true;
}
catch
{
flag = false;
}
finally
{
if (response != null)
response.Close();
}

return flag;
}
Posted 29 Dec, 2011 07:56:17 Top
Sergey Grischenko


Add-in Express team


Posts: 7224
Joined: 2004-07-05
To open a local HTML page you just need to set the path to the web page in the Navigate method.
E.g.

this.IEApp.Navigate("d:\\Temp\\MyIEAddon13\\MyIEAddon13\\HTMLPage1.htm", ref dummy, ref dummy, ref dummy, ref dummy);
Posted 29 Dec, 2011 08:02:14 Top