开发者

MVC Site versus Virtual Application Routing

We use TFS to deploy our applications to multiple environments (Dev, QA, Prod). Simple enough, our Dev and QA environments have URLS like dev.domain/APPLICATION and qa.domain/APPLICATION. So we have a single site with each application as a virtual application.

However in production, they want each application to be its own site, such as APPLICATION.domain.com... Grrr! In Visual Studio, the application's properties is configured to be in a "Virtual Path". I"m not sure how I should go about this issue. The appliation contains code such as: <a href='/APPLICATION/File/Download?id=<#= PkFileId #>'><#= Name #></a> which causes problems in production since its not in a virtual application.

I could make a site called application.domain.com with an empty directory. Then add a Virtual Application, but then I would have 开发者_JAVA百科to put a redirect in the root of the site to go to the virtual application. Or perhaps I can somehow configure the application? Not sure what my options are... Any suggestions are appreciated!


The appliation contains code such as:

<a href='/APPLICATION/File/Download?id=<#= PkFileId #>'><#= Name #></a>

ASP.NET MVC applications should not contain code like that (a code in which urls are hardcoded). In ASP.NET MVC applications you should always use HTML and Url helpers:

@Html.ActionLink(
    Model.Name, 
    "Download", 
    "File", 
    new { id = Model.PkFileId }, 
    null
)

This way it is certain that no matter how your routes are configured or under which virtual directory your application is hosted, it should work.


UPDATE:

After your comment it looks like you are using the Telerik Grid. In this case you may try something along the lines to generate proper anchors:

columns
    .Bound(x => x.PkFileId)
    .ClientTemplate(
        Html.ActionLink(
            "<#= Name #>", 
            "Download", 
            "File", 
            new { id = "<#= PkFileId #>" }, 
            null
        ).ToString()
    )
    .Title("");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜