PDA

View Full Version : سوال: شکل با Url Rewriting و Google



mahdi_negahi
دوشنبه 04 آذر 1387, 12:58 عصر
سلام

من سایتی درست کردم که در آن از یک URL Rewriting استفاده میکنم ، کد این URL Rewriting را در زیر آورده ام ، مشکل اینجاست که بعد از 2 هفته تمام لینک های سایت من ایندکس شده در گوگل ولی این لینک خیر ، در گوگل اکانت من برای این URL خطای Network unreachable گذاشته که اصلا ممکن نیست چون اگر سرور down بوده پس چرا بقیه را کرده در زیر هم عکس گوگل اکانت من را مشاهده میکنید

http://i34.tinypic.com/2rr8b6d.jpg



public class UrlReWriting : IHttpModule
{
private Regex ServiceNameRegex = new Regex(@"^.*/Service/.*/Default\.aspx$".ToLower());
private Regex FocusPageRegex = new Regex(@"^.*/Service/.*/Default\.aspx\?Id=\d+$".ToLower());
private Regex ibcPage = new Regex(@".*\.aspx.*".ToLower());
public UrlReWriting()
{
}

#region IHttpModule Members

public void Dispose()
{

}

public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}

void context_BeginRequest(object sender, EventArgs e)
{

HttpApplication ap = sender as HttpApplication;
if (ServiceNameRegex.IsMatch(ap.Context.Request.RawUr l.ToLower()) && !ap.Context.Request.RawUrl.Contains(IranBuyCenter. Common.CommonsBehavior.ReturnURL))
{
IList<ServiceCategoryDTO> dtoLists = new ServiceCategoryBLL().Select(0);
int Id = 0;
string CurrentUrl = ap.Context.Request.RawUrl.ToLower();
CurrentUrl = CurrentUrl.Replace("/Default.aspx".ToLower(), "");
CurrentUrl = CurrentUrl.Replace((HttpContext.Current.Request.Ap plicationPath + "/Service/").ToLower(), "");
CurrentUrl = CurrentUrl.ToLower();
CurrentUrl = CurrentUrl.Trim();

Regex Service;
foreach (ServiceCategoryDTO currentDTO in dtoLists)
{

string Name = currentDTO.EnglishName.ToLower();
Service = new Regex(".*" + Name + ".*");
if (Service.IsMatch(CurrentUrl))
{
Id = currentDTO.Id;
}
}
ap.Context.RewritePath("~/ServiceProduct.aspx", "", "ItemId=" + Id.ToString());
}
else if (FocusPageRegex.IsMatch(ap.Context.Request.RawUrl. ToLower()) && !ap.Context.Request.RawUrl.Contains(IranBuyCenter. Common.CommonsBehavior.ReturnURL))
{
string ID = (ap.Context.Request.RawUrl.Split('='))[1];
ap.Context.RewritePath("~/FocusServiceProduct.aspx", "", "ItemId=" + ID);
}
else if (ibcPage.IsMatch(ap.Context.Request.RawUrl.ToLower ()))
{
string Url = ap.Context.Request.RawUrl;
Url = Url.Replace("aspx", "aspx");
if (Url.Contains(IranBuyCenter.Common.CommonsBehavior .ReturnURL))
{

string BaseUrl = Url.Substring(0, Url.IndexOf(".aspx")) + ".aspx";
string ContinueString = Url.Substring(Url.IndexOf(IranBuyCenter.Common.Com monsBehavior.ReturnURL));

ap.Context.RewritePath(BaseUrl.Replace("aspx", "aspx") + "?" + ContinueString);
}
else
ap.Context.RewritePath(Url.Replace(".aspx", ".aspx"));
}
//;
//if (ap.Context.Cache["OnlineServiceName"] == null)
//{
// IranBuyCenter.Common.UrlRewriterHelper urlCheaker = new IranBuyCenter.Common.UrlRewriterHelper(ap.Context. Server.MapPath("~/App_Data/OnlineServiceHelper.xml"));
// dtoLists = urlCheaker.GetAll();
// ap.Context.Cache["OnlineServiceName"] = dtoLists;
//}
//else
//{
// dtoLists = (IList<OnlineServiceDTO>)ap.Context.Cache["OnlineServiceName"];
//}
//if (ap != null)
//{
// if (ap.Context.Request.RawUrl.ToLower().Contains(_Onl ineServiceName_PageName.ToLower()))
// {

// foreach (IranBuyCenter.DTO.OnlineServiceDTO item in dtoLists)
// {
// if (ap.Context.Request.RawUrl.ToLower().Contains(item .EnglishName.ToLower()))
// {
// ap.Context.RewritePath("ShowService.aspx", "", "ItemId=" + item.Id.ToString());
// }
// }
// }
// if (ap.Context.Request.RawUrl.ToLower().Contains(_Onl ineServiceRole_PageName.ToLower()))
// {
// string Id = GetID(ap.Context.Request.RawUrl);
// if (!string.IsNullOrEmpty(Id))
// ap.Context.RewritePath("ShowRoles.aspx", "", "ItemId=" + Id);
// }
//}
}

private string GetBaseUrl()
{
string urlBase = HttpContext.Current.Request.Url.GetLeftPart(UriPar tial.Authority) +
HttpContext.Current.Request.ApplicationPath;
return urlBase;
}
#endregion
}