【发布时间】:2014-05-10 18:39:00
【问题描述】:
我刚刚将我的网站框架从 2.0 更改为 4.0。我收到错误 HTTP 错误 404.0 - 每当我尝试打开 URL 重写网页时都找不到。
在 Framework 2.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>
【问题讨论】:
-
单步执行代码会发生什么?它应该重写的地方会发生什么?您收到错误消息吗?
-
如果我通过 VS2010 运行它,那么它工作正常。但如果我在 IIS 或服务器上使用它,则会显示 404 错误。
-
可能有点远,但是应用程序池以什么模式运行?经典还是集成(尝试切换)?哪个 IIS 版本?除了改变目标框架,你还做了哪些改变?
-
@scheien,我将应用程序池从经典更改为集成,它开始工作。 :)
-
太棒了!很高兴你让它工作:-)
标签: c# asp.net iis url-rewriting url-routing