我改变了我的global.asax来注册这样的路线: 公共类MvcApplication
Inherits System.Web.HttpApplication
Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
' MapRoute takes the following parameters, in order:
' (1) Route name
' (2) URL with parameters
' (3) Parameter defaults
routes.MapRoute( _
"Default", _
"{controller}.aspx/{action}/{id}", _
New With {.controller = "Home", .action = "Index", .id = ""} _
)
routes.MapRoute( _
"Root", _
"", _
New With {.controller = "Home", .action = "Index", .id = ""} _
)
End Sub
Sub Application_Start()
RegisterRoutes(RouteTable.Routes)
End Sub
End Class
一切正常但根路径(www.mysite.com)不起作用,我收到如下错误:“网站拒绝显示此网页HTTP 403”
我怎么能摆脱那个?
答案 0 :(得分:3)
如果您添加带有以下Page_Load代码的Default.aspx页面,它将起作用:
public void Page_Load(object sender, System.EventArgs e)
{
// Change the current path so that the Routing handler can correctly interpret
// the request, then restore the original path so that the OutputCache module
// can correctly process the response (if caching is enabled).
string originalPath = Request.Path;
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
HttpContext.Current.RewritePath(originalPath, false);
}
答案 1 :(得分:3)
虽然Nebakanerer的解决方案适用于网站的根目录,但它不适用于任何建议子文件夹的网址。
所以我没有使用Default.aspx文件选项,而是将基于IIS6的网站中的所有通配符映射到aspnet_isapi.dll。基本上使ASP.NET处理所有请求。