Html.ActionLink不适用于生产环境 [英] Html.ActionLink not working in production environment
问题描述
我目前正在开发一个MVC4项目,该项目正在部署到 IIS6
托管环境。
我使用 Html.ActionLink()
在我的页面上生成链接。
例如:
@ Html.ActionLink(Home Link,Index,Admin)
当我在本地运行应用程序时(即触及 http:// localhost:yyy ),链接生成正常:
< a href =/ Admin / Index > Home Link< / a>
当我在生产环境中运行它时:
< a href =>主页链接< / a>
正如您所见,链接没有 href
为它生成。
我认为这可能是路由问题,但是当我尝试访问浏览器中的一个页面: admin / edit / 45
,或者一个使用自定义路由绑定的页面: sf / 24
,这两项工作都很好;他们引导我到我期望的页面。
我非常想法,并且不确定如何解决。
任何帮助,将不胜感激。
谢谢,
我为此添加了一笔赏金,希望它可以帮助您获得答案。我怀疑这个问题可以帮助其他人,因为我似乎没有做任何突破性的事情。
UPDATE 24/09/14
这是使用内置web服务器(Cassini?)在VS2010 SP1中开发的。
然后,我发布(使用Visual Studio的内置选项)到运行IIS6的服务器。
目录结构包含类似于:
App_Start
资产
类
内容
控制器
DomainModel
脚本
服务
共享资源
ViewModels
Views
(即没有任何内容与任何链接的名称相匹配)。
除此之外,捆绑似乎可行。例如: 使用这个(VB)Razor: @ Scripts.Render(〜/ bundles / adminjs) $ b
@ Html.ActionLink(View,Display,Form,New With {.id = 72},没有)
< br />
@ Html.RouteLink(View,Default,new with {.controller =Form,.action =Display,.id = 72})
我得到以下输出。
在VS10 / Chrome中(本地):
< a href =/ Form / Display / 72>检视< / a>
< br>
< a href =/ Form / Display / 72>查看< / a>
在IIS6 / Chrome(服务器)中:
< a href =>检视< / a>
< br>
< a href =>检视< / a>
..给它增加了更多的神秘感,它不会提取路线..
您可能需要查看 SO ,以查看您是否遇到了与定义路线和默认路线的方式相同的问题。
I'm currently working on an MVC4 project, that is being deployed to an IIS6
hosting environment.
I am using Html.ActionLink()
to generate links on my page.
eg:
@Html.ActionLink("Home Link", "Index", "Admin")
When I run the application locally (ie hitting http://localhost:yyy
), the link is generated fine:
<a href="/Admin/Index">Home Link</a>
When I run it in the production environment however:
<a href="">Home Link</a>
As you can see, the link does not have a href
generated for it.
I thought it might be an issue with routing, but when I try to visit a page in the browser: admin/edit/45
, or one using a custom route binding: sf/24
, both of these work fine; they direct me to the page I expect.
I'm pretty out of ideas, and not sure on how to resolve.
Any help, would be greatly appreciated.
Thanks,
I've added a bounty to this, in the hope that it might help get an answer. I suspect this problem could help others, as I don't seem to be doing anything too groundbreaking.
UPDATE 24/09/14
This is being developed in VS2010 SP1, using the built-in web server (Cassini?).
I am then publishing (using the in-built options of Visual Studio) to the server, which is running IIS6.
The directory structure contains something similar to:
App_Start
Assets
Classes
Content
Controllers
DomainModel
Scripts
Services
SharedAssets
ViewModels
Views
(ie. nothing in there matches the names of any links).
On top of this, bundling seems to work. eg: @Scripts.Render("~/bundles/adminjs")
Using this (VB) Razor:
@Html.ActionLink("View", "Display", "Form", New With { .id = 72 }, Nothing)
<br />
@Html.RouteLink("View", "Default", new with { .controller = "Form", .action = "Display", .id = 72 })
I get the following output..
In VS10/Chrome (local):
<a href="/Form/Display/72">View</a>
<br>
<a href="/Form/Display/72">View</a>
In IIS6/Chrome (server):
<a href="">View</a>
<br>
<a href="">View</a>
..adding more to the mystery of it not picking up the routes..
You may want to take a look at this SO to see if you are experiencing the same issue regarding the way that your routes and default routes are defined.
这篇关于Html.ActionLink不适用于生产环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!