C# 使用global.asax时找不到资源
在网站窗格中上载我的网站后,我收到此错误 找不到资源 描述:HTTP404。您正在寻找的资源或其 依赖项可能已被删除、名称已更改或已被删除 暂时不可用。请查看下面的URL并进行修改 确保它拼写正确 请求的URL:/.aspx 我认为它与global.asax有关,因为当我将它从主机上删除时,我的网站会立即运行 我的global.asax代码C# 使用global.asax时找不到资源,c#,asp.net,routing,global-asax,C#,Asp.net,Routing,Global Asax,在网站窗格中上载我的网站后,我收到此错误 找不到资源 描述:HTTP404。您正在寻找的资源或其 依赖项可能已被删除、名称已更改或已被删除 暂时不可用。请查看下面的URL并进行修改 确保它拼写正确 请求的URL:/.aspx 我认为它与global.asax有关,因为当我将它从主机上删除时,我的网站会立即运行 我的global.asax代码 namespace officeWeb { public class Global : System.Web.HttpApplication
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,因为它缺少实际的文件名,并且只有扩展名
您需要调试代码,并查看应用程序_BeginRequest中的变量值是否符合您的预期。很可能不是。谢谢你的asnswer,但当我删除global.asax中的代码并将空gloabl.asax放在根目录中时,我得到了相同的错误,在本地主机中它的工作正确,我感到困惑。没有global.asax它能工作吗?没有global.asax它不能工作吗?在你的问题中,你说它没有工作,现在你说它没有工作。当我从主机上删除它工作时,当我将它添加到主机的dosent工作时,我也本地托管它的工作