In dealing a requirement of Search Engine Optimization based module i drag my self in a requirement of verifying whether user enters URL with prefix of
Http:// or not...if he enters it's all ok...but if he not prefix his URL with
Http:// my code must add that as prefix to entered URL by user.....and also i need to check whether URL contains
WWW(with prefix)...if not my code must add this
WWW to entered URL by user....I had done a really hard work on this but i can't fix it....it will be more broad welcome from my side for any advice's or suggestions towards achieving my requirement ...using java script...:)
here is my controller code to verify the sitemap and robots of the provided url
public string GetAllSemData(string givenurl)
{
var retval = string.Empty;
Seoproperties obj = new Seoproperties();
StringBuilder sb = new StringBuilder();
Dictionary<string, string> results = new Dictionary<string, string>();
#region Sitemap.xml and robots.txt
string[] names = new string[2] { "/sitemap.xml", "/robots.txt" };
sb.AppendLine("<table id='tblLists' class='gridtable' width='100%'>");
sb.AppendLine("<thead><tr>");
sb.AppendLine("<th>SEO </th>");
sb.AppendLine("<th>RESULTS</th>");
sb.AppendLine("</tr></thead>");
sb.AppendLine("<tbody>");
foreach (var item in names)
{
// string addHttp = "http://";
try
{
WebRequest request = HttpWebRequest.Create("" + givenurl + "" + item + "");
//HttpWebRequest.Create("http://" + givenurl + "" + item + "");
request.Method = "HEAD"; // Just get the document headers, not the data.
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
if (response.StatusCode == HttpStatusCode.OK)
{
retval = (item + " exists!");
if (retval == "/sitemap.xml exists!")
{
//results.Add("XML Sitemap", "Great,you site has an XML Sitemap");
sb.AppendLine("<tr>");
sb.AppendLine("<td><img src='images/1382554024_ok-green.png' alt='ok' />XML Sitemap</td>");
sb.AppendLine("<td>Great,you site has an XML Sitemap</td>");
sb.AppendLine("</tr>");
}
else
{
sb.AppendLine("<tr>");
sb.AppendLine("<td><img src='images/1382554024_ok-green.png' alt='ok' />robots.txt</td>");
sb.AppendLine("<td>Great,your site has an robots.txt file</td>");
sb.AppendLine("</tr>");
// results.Add("robots.txt", "Great,your site has an robots.txt file");
}
}
else
{
// Some other HTTP response - probably not good.min
// Check its StatusCode and handle it.
}
}
}
catch (WebException ex)
{
//HttpWebResponse webResponse = new HttpWebResponse();
HttpWebResponse webResponse = (HttpWebResponse)ex.Response;
// Determine the cause of the exception, was it 404?
if (webResponse.StatusCode == HttpStatusCode.NotFound)
{
MessageBox.Show(webResponse.StatusDescription);
retval = (item + " does'nt exists!");
if (retval == "/sitemap.xml does'nt exists!")
{
sb.AppendLine("<tr>");
sb.AppendLine("<td><img src='images/cross_circle.png' />XML Sitemap</td>");
sb.AppendLine("<td>Your Website does not have an XML Sitemap kindly create it.</td>");
sb.AppendLine("</tr>");
//results.Add("XML Sitemap", "Your Website does not have an XML Sitemap kindly create it.");
}
else
{
sb.AppendLine("<tr>");
sb.AppendLine("<td><img src='images/cross_circle.png' />robots.txt</td>");
sb.AppendLine("<td>Your Website does not have Robots.txt file kindly create it.</td>");
sb.AppendLine("</tr>");
//results.Add("robots.txt", "Your Website does not have Robots.txt file kindly create it.");
}
}
else
{
// Handle differently...
retval = (ex.Message);
}
}
}
here is my JavaScript code to verify the url
function SubmitUrl() {
var addHttp = 'http://';
var givenurl = addHttp+$("#txtUrl").val();
$.ajax({
url: "Analysis/Checkfilesexitsornot?givenurl=" + givenurl,
type: 'POST',
cache: false,
data: '',
success: Checkingfilesexits,
failure: function myfunction(response) {
alert(response.d);
}
});
return false;
}
in my JavaScript code i had taken a variable and added http:// to the given URL variable but i need to check both Http:// & WWW.. to check and add to the given Url...the o?p of this code will be displaying information about given URL website (title,content,robots,XML Sitemap,description of the web page of given URL in a table)he i had taken table in sb(string builder)and adding the columns of Seo,Results....2ND table is MetaData,Results of the website of given Url...