问题描述
我有一个在IIS 7.5上运行的MVC4/.Net 4网站.在我的web.config文件中,我的代码块中包含以下内容:
I have a MVC4/.Net 4 website running on IIS 7.5. In my web.config file I have the following in my block:
<urlMappings enabled="true">
<add url="~/2013calendar" mappedUrl="~/CustomerService/RequestPocketCalendar" />
<add url="~/teachers" mappedUrl="http://www.somexternalsite.com/teachers/" />
</urlMappings>
本地重定向都可以很好地工作,但是任何重定向到站点之外的内容(例如上例中的/teachers链接返回"http://www.somexternalsite.com/teachers")都不是有效的虚拟路径.
The local redirects all work great, but anything that is redirecting off the site, such as the /teachers link in the above example return "http://www.somexternalsite.com/teachers" is not a valid virtual path.
我在这里想念什么?
推荐答案
我最终创建了一个页面来处理外部重定向,如下所示:
Well I ended up creating a page to handle external redirects such as follows:
redirect.aspx
redirect.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
var page = Request.QueryString["page"];
Response.Redirect("http://"+page);
}
</script>
因此在我的web.config中,我引用了如下外部文件:
So in my web.config I have external files referenced as such:
<add url="~/teachers" mappedUrl="~/redirect.aspx?page=www.somexternalsite.com/teachers/" />
太棒了!
这篇关于Web.config urlMappings-适用于本地页面,不适用于远程页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!