MVC文件夹下默认文档
因此,在 IIS 中,您可以将所有站点文件夹的默认文档设置为“index.aspx”。
在 MVC 中,我如何跨 a) 所有目录执行此操作,或者一次失败 b) 一个目录。
我在 [Views]/[Search]/[index.aspx] 中有一个页面
此网址有效 - www.[mysite]/search/index 但我无法让它在 - www.[mysite]/search 下工作
我尝试将其添加到 global.asax >注册路线
routes.MapRoute(
"Search",
"{action}",
new { controller = "Search", action = "Index" }
);
So in IIS you can set the default document for all site folders to be say "index.aspx".
In MVC how do I do this across a) all directories or failing that b) one directory at a time.
I have a page in [Views]/[Search]/[index.aspx]
This url works - www.[mysite]/search/index
but I can't get it to work under - www.[mysite]/search
I have tried adding this into global.asax > RegisterRoutes
routes.MapRoute(
"Search",
"{action}",
new { controller = "Search", action = "Index" }
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MVC 不使用默认文档,而是使用默认路由。
您上面的路线向我们表明,当有人访问您的网站 (http://example.com) 时,默认页面将是
search
目录中包含的Index
视图。使用新的 MVC 项目生成的默认路由如下所示
这意味着您的路由结构将类似于
MVC doesn't use a default document, but a default route.
Your route above shows us that the default page when someone visits your website (http://example.com) will be the
Index
view contained within thesearch
directory.The default route that gets generated with a new MVC project looks like this
What this means is that your routing structure would look like
通常你不需要这条路线。默认路由应该可以正常工作,因为它指定了默认控制器和操作,您可以对其进行修改以满足您的要求。因此,如果用户请求
/
这个默认控制器和操作应该被执行。这在 IIS7 上可以开箱即用,但在 II6 上则不起作用,因为默认情况下不能使用无扩展名的 url。您可以查看以下 博客文章(如果您在 IIS6 上运行)。Normally you don't need this route. The default route should work fine as it specifies a default controller and action which you could modify to match your requirements. Thus if the user requests
/
this default controller and action should be executed. This would work out of the box on IIS7 but on II6 it won't work because you cannot have extensionless urls by default. You might take a look at the following blog post if you are running on IIS6.