使用MVC /迪朗达尔应用程序路由问题,并位于IIS子文件夹 [英] Routing issue in application using MVC/Durandal and located in IIS subfolder
问题描述
I'm寻找我的问题,我在标题中提到的解决方案。
首先你需要知道我有两位MVC应用程序上的IIS发布。第一个应用程序是怎样的一个中央管理系统,所以我成立了一个在IIS中被称为管理网站。第二个应用程序是在网站管理嵌入应用程序(子)一个MVC的网上商店。
I´m looking for a solution for my problem I mentioned in the title. First of all you need to know that I have two MVC applications published on an IIS. The first application is kind of a central management system so I set up a Site called "Management" in IIS. The second app is a MVC web shop embedded as application (subfolder) in Site "Management".
有关店铺使用迪朗达尔我创建了一个MVC应用程序。
For the shop I created an MVC application using durandal.
现在好像我有一个路由问题。当我进入网站的管理定义的URL我看到了集中管理,这是完全正确的。网址如下:
Now it seems like I have a routing problem. When I enter the URL defined in Site "Management" I see the central management, which is completely right. The URL looks like:
http://mySite.com/
当我试图访问我的店我只是去到以下网址:
When I try to visit my shop I just go to the following URL:
http://mySite.com/Shop
此应用程序只包含一个的 .cshtml 的文件,该文件renderes使用迪朗达尔店铺的不同的页面。这也适用,但是当我进入我的凭据,迪朗达尔似乎加入路由,因为它增加了一个#/的URL。会发生什么事是那I'm重定向到我的父应用程序的HomeController索引视图( http://mySite.com ) 。那是我不想要的东西!
This application only contains one .cshtml file which renderes the different pages of the shop using Durandal. This also works, but when I enter my credentials, Durandal seems to join the routing because it adds an "#/" to the URL. What happens then is that I´m redirected to the HomeController index view of my parent application (http://mySite.com). Thats what I don't want!
你们谁能帮助我在这个问题?
Can anyone of you help me in this issue?
我要补充一点,我没有任何局部问题,当我跑店,所以我猜子的事情和/或迪朗达尔是这种行为的原因。
I need to add that I don't have any problems locally when I run the shop so I guess the subfolder thing and/or durandal is the cause of this behavior.
在此先感谢!
Yheeky
推荐答案
是的,它的子文件夹商店是造成这种行为。我有完全相同的问题,我开发的应用程序。下面是我使用的解决方案。我觉得这是一个有点黑客,但它的工作。
Yep, it's the subfolder "Shop" that's causing this behavior. I had the exact same problem with the applications I was developing. Here's the solution I used. I feel like it's sort of a hack, but it does the job.
首先,挖成RequireJS配置文件后,我想通了,如何在变量传递给在 main.js
文件的模块。
First, after digging into the RequireJS config documentation, I figured out how to pass on variables to a module in the main.js
file.
requirejs.config({
paths: {
...
},
config: {
'modules/routes': {
subfolder: 'Shop'
}
}
});
我再在其唯一的项目中创建一个 routes.js
模块下 /应用/模块/
文件夹责任是构建网址,我的应用程序的其余部分。在这一模块中,我写了确定脚本是否在本地或Web服务器上运行的功能。在此基础上,它则使用子文件夹
变量我通过它在RequireJS配置构建根URL的应用程序将使用的所有路由。
I then created a routes.js
module under an /App/modules/
folder in the project whose sole responsibility it to construct URLs for the rest of my application. Within that module, I wrote a function that determines whether or not the script is running locally or on a web server. Based on that, it then uses the subfolder
variable I passed it in the RequireJS config to construct the root URL the application will use for all routing.
define(['module'],
function (module) {
// if the application is being hosted on http://localhost, do not include the application name
var domain = window.location.protocol + '//' + window.location.host,
root = (window.location.hostname !== 'localhost') ? domain + '/' + module.config().subfolder : domain;
function getUrl(controller, action) {
return (action) ? root + '/' + controller + '/' + action : root + '/api/' + controller;
}
return {
getUrl: getUrl,
cart: getUrl('Home', 'Cart'),
...
}
});
请注意,您在传递为了从RequireJS配置读取的变量。模块
这篇关于使用MVC /迪朗达尔应用程序路由问题,并位于IIS子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!