我们正在努力让html5mode与AngularJs一起工作,最后一个障碍是重新创建IIS does这样的礼貌重定向:
请求
GET http://localhost/foo HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Host: ws7-agentry2
IIS响应
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Location: http://localhost/foo/
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Fri, 18 Jul 2014 17:09:20 GMT
Content-Length: 147
<head><title>Document Moved</title></head>
<body><h1>Object Moved</h1>This document may be found <a HREF="http://localhost/foo/">here</a></body>
问题是,无论请求是否包含尾部斜杠,Nancy管道中的请求对象都是相同的。由于我们无法区分这两者,因此我们无法在不导致无限循环重定向的情况下返回重定向。我们已经尝试使用url重写来实现这一点,但无济于事,理想情况下我想得到原始URL。
提前致谢
答案 0 :(得分:0)
如果其他人需要获得相同的结果,那就是让html5mode与IE9&amp; NancyFx,不得不像本文shows那样构建一个httpmodule,尽管我认为标题是错误的:
public class CourtesyRedirectModule : IHttpModule {
public void Dispose() {}
public void Init(HttpApplication context) {
context.BeginRequest += context_BeginRequest;
}
private void context_BeginRequest(object sender, EventArgs e) {
if (HttpContext.Current.Request.Url.PathAndQuery.Equals(HttpContext.Current.Request.ApplicationPath))
HttpContext.Current.Response.Redirect(HttpContext.Current.Request.ApplicationPath + "/");
}
}