2014-03-31 75 views
0

我刚刚将我的网站框架从2.0更改为4.0。并且我收到错误HTTP错误404.0 - 每当我尝试打开URL重写网页时都找不到。

它在Framework 2.0的时候工作正常,现在不知道什么是错。我有谷歌很多东西,但没有得到任何适当的解决方案。

请帮我解决问题。

我的代码如下:
URL重写显示404错误后,从2.0升级到4.0

http://www.theprojectjugaad.com/PlacementAssistance.html -> Not Working 
http://www.theprojectjugaad.com/PlacementAssistance.aspx -> Working 

的Global.asax:

void Application_Start(object sender, EventArgs e) 
    { 
     RegisterRoutes(); 
    } 

    void Application_BeginRequest(object sender, EventArgs ex) 
    { 
     if (!Request.Url.Host.Equals("localhost") 
      && !Request.Url.Host.ToString().Contains("www.theprojectjugaad.com") 
      && Request.Url.Host.ToString().Contains("theprojectjugaad.com")) 
     { 
      string Result = string.Concat(
      "http://", 
      Request.Url.Authority.Replace("theprojectjugaad.com", "www.theprojectjugaad.com"), 
      HttpContext.Current.Response.ApplyAppPathModifier(Request.Path), 
      Request.Url.Query); 

      HttpContext.Current.Response.Redirect(Result, true); 
     } 
    } 

    private static void RegisterRoutes() 
    { 
     System.Web.Routing.RouteTable.Routes.Add(
       "PlacementAssistance", new System.Web.Routing.Route("PlacementAssistance.html", 
            new RouteHandler("~/PlacementAssistance.aspx"))); 
    } 

RouteHandler.cs:

public RouteHandler(string virtualPath) 
    { 
     _virtualPath = virtualPath; 
    } 

    public IHttpHandler GetHttpHandler(RequestContext requestContext) 
    { 
     var display = BuildManager.CreateInstanceFromVirtualPath(
         _virtualPath, typeof(Page)) as IDisplay; 
     return display; 
    } 

    string _virtualPath; 

IDisplay.cs:

public interface IDisplay : IHttpHandler 
{ 

} 

的web.config:

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="Session" /> 
     <add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition="" /> 
    </modules> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <handlers> 
     <remove name="UrlRoutingHandler" /> 
    </handlers> 
    <rewrite> 
     <rules> 
     <remove name="Plesk. SEO-safe redirect for http://www.theprojectjugaad.com" /> 
     <rule name="Plesk. SEO-safe redirect for http://www.theprojectjugaad.com" enabled="false" patternSyntax="Wildcard" stopProcessing="true"> 
      <match url="*" /> 
      <conditions> 
      <add input="{HTTP_HOST}" pattern="www.theprojectjugaad.com" /> 
      <add input="{HTTPS}" pattern="OFF" /> 
      </conditions> 
      <serverVariables /> 
      <action type="Redirect" url="http://theprojectjugaad.com/{R:1}" /> 
     </rule> 
     </rules> 
    </rewrite> 
    </system.webServer> 
+0

如果单步执行代码会发生什么?它应该重写的地方会发生什么?你有错误信息吗? – scheien

+0

如果我通过VS2010运行它,那么它工作正常。但是,如果我在IIS或服务器上使用它,它显示404错误。 –

+1

也许是一个长镜头,但应用程序池运行的是什么模式?经典还是集成(尝试切换)?哪个IIS版本?除了改变目标框架之外,你还做了哪些改变? – scheien

回答

0

的网址是什么不工作?

我看到的是您已将.html的网址更正为.aspx,并且正常工作。

+0

它是dotnet所以它的主要扩展名是.aspx,通过使用URL重写,我打开它为.html –