2014-07-24 42 views
0

我在网站panle上传我的网站后出现此错误 无法找到资源。使用global.asax时找不到资源

说明:HTTP 404。您正在寻找(或它的 的一个依赖项)可能已被删除的资源,有其名称更改,或者是 暂时不可用。请检查以下URL并确定 拼写正确。

请求的URL:/.aspx

,因为当我从主机中删除我的网站运行currectly 我的Global.asax代码,我认为它于Global.asax中相关

namespace officeWeb 
{ 
    public class Global : System.Web.HttpApplication 
    { 

     protected void Application_Start(object sender, EventArgs e) 
     { 
      RegisterRoutes(RouteTable.Routes); 

     } 

     protected void Session_Start(object sender, EventArgs e) 
     { 

     } 

     protected void Application_BeginRequest(object sender, EventArgs e) 
     { 
      String fullOrigionalpath = Request.Url.ToString(); 
      String[] sElements = fullOrigionalpath.Split('/'); 
      String[] sFilePath = sElements[sElements.Length - 1].Split('.'); 

      if (!fullOrigionalpath.Contains("__browserLink")) 
      { 
          //Rewrite 
      if (!fullOrigionalpath.Contains(".aspx") && sFilePath.Length == 1) 
      { 
       Context.RewritePath(sFilePath[0] + ".aspx"); 
      } 
      } 

     } 

     protected void Application_AuthenticateRequest(object sender, EventArgs e) 
     { 

     } 

     protected void Application_Error(object sender, EventArgs e) 
     { 

     } 

     protected void Session_End(object sender, EventArgs e) 
     { 

     } 

     protected void Application_End(object sender, EventArgs e) 
     { 

     } 
     public static void RegisterRoutes(RouteCollection routes) 
     { 

      routes.Add("", 
       new Route("root/pages/service/{*pathInfo}", new WebServiceRouteHandler("~/root/config/services.asmx"))); 

     } 


     public class WebServiceRouteHandler : IRouteHandler 
     { 
      private static IHttpHandlerFactory ScriptHandlerFactory; 
      static WebServiceRouteHandler() 
      { 
       var assembly = typeof(System.Web.Script.Services.ScriptMethodAttribute).Assembly; 
       var type = assembly.GetType("System.Web.Script.Services.ScriptHandlerFactory"); 
       ScriptHandlerFactory = (IHttpHandlerFactory)Activator.CreateInstance(type, true); 
      } 

      private string virtualPath; 
      public WebServiceRouteHandler(string virtualPath) 
      { 
       this.virtualPath = virtualPath; 
      } 

      public IHttpHandler GetHttpHandler(RequestContext requestContext) 
      { 
       string pathInfo = requestContext.RouteData.Values["pathInfo"] as 
       if (!string.IsNullOrWhiteSpace(pathInfo)) 
        pathInfo = string.Format("/{0}", pathInfo); 

       requestContext.HttpContext.RewritePath(this.virtualPath, pathInfo, requestContext.HttpContext.Request.QueryString.ToString()); 
       var handler = ScriptHandlerFactory.GetHandler(HttpContext.Current, requestContext.HttpContext.Request.HttpMethod, this.virtualPath, requestContext.HttpContext.Server.MapPath(this.virtualPath)); 
       return handler; 
      } 
     } 
    } 
} 

什么我应该怎么做? 请帮助我

回答

0

如果您查看请求的URL,它会显示/.aspx。这是一个无效的URL,因为它错过了实际的文件名并且只有扩展名。

您需要调试您的代码并查看Application_BeginRequest()中的变量值是否是您期望的值。可能它们不是。

+0

感谢您的关注,但是当我在global.asax中删除我的代码时,在根中放入了空gloabl.asax我得到同样的错误,在本地主机中它的工作正确 –

+0

我很困惑。它没有global.asax工作,还是不工作没有?在你的问题中,你说它没有工作,现在你说它没有工作。 – Nzall

+0

当我从主机中删除它的工作,并且当我添加这个主机它是剂量工作(我本地主机它的工作) –