使用global.asax时无法找到该资源
本文关键字:资源 global asax 使用 | 更新日期: 2023-09-27 18:14:38
我在网站面板上传我的网站后,我得到这个错误无法找到资源。
描述:HTTP 404。您正在查找的资源(或其中之一)依赖项)可以被删除,如果它的名称被更改,或者是暂时不可用。请查看以下网址并制作确保拼写正确。
请求的URL:/.aspx
我认为这与全球有关。Asax,因为当我从主机我的网站运行当前删除它我的世界。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;
}
}
}
}
我该怎么办?
如果您查看请求的URL,它将读取/.aspx
。这是一个无效的URL,因为它缺少实际的文件名,只有扩展名。
您需要调试您的代码,看看Application_BeginRequest()
中的变量值是否符合您的期望。很可能不是。