【发布时间】:2013-11-30 13:22:54
【问题描述】:
我已将 FriendlyUrls nuget 包添加到 WebForm 应用程序。
在 RegisterRoutes 我有:
var settings = new FriendlyUrlSettings();
//settings.AutoRedirectMode = RedirectMode.Off;
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings);
我创建了 2 个页面 WebForm1.aspx 和 WebForm2.aspx
在 WebForm1.aspx 上,我在头部引用了 jQuery v1.9.1,只是在正文的默认 div 标签内添加了以下内容:
<div id="dvResult"></div>
<script type="text/javascript">
$(function() {
$.fpm("GetCategories", '', function (res) {
$("div#dvResult").html(res.d);
}, function (xhr, ajaxOptions, thrownError) {
$("div#dvResult").html("<b>" + thrownError + "</b><br/>Status: " + xhr.status + "<br/>" + xhr.responseText);
});
});
$.fpm = function fpm(methodName, arguments, onSuccess, onError) {
var proto = (("https:" == document.location.protocol) ? "https://" : "http://");
var hostname = window.location.hostname;
if (window.location.port != 80)
hostname = window.location.hostname + ":" + window.location.port;
var loc = proto + "" + hostname + "/WebForm2.aspx";
$.ajax({
type: "POST",
url: loc + "/" + methodName,
data: "{" + arguments + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: onSuccess,
error: onError
});
};
</script>
WebForm2.aspx在将文件添加到项目后保持标准,除了在后面的代码中添加了1个方法:
[System.Web.Services.WebMethod(EnableSession = false)]
public static string GetCategories()
{
return "hi";
}
当我运行 WebForm1.aspx 页面时,我得到以下结果:
{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}
在 fiddler 中查看请求时,我可以看到友好的 url 没有去除 .aspx 扩展名(这是一件好事):
http://localhost:14918/WebForm2.aspx/GetCategories
但是,如上所示,FriendlyUrlSettings 将 AutoRedirectMode 设置为 RedirectMode.Permanent,当您取消注释 RedirectMode.Off 行并将 Permanent 注释掉时,您实际上会在屏幕上打印结果“Hi”。
任何人有任何想法可能是什么原因或如何为路线添加排除项?
我尝试过关注,但它似乎不会以任何方式影响我不断得到的 401 结果:
//routes.Add(new Route("*Remote.aspx*", new StopRoutingHandler()));
//routes.Ignore("{remote}", new { remote = @".*\Remote.aspx(/.)?" });
【问题讨论】:
标签: c# asp.net jquery webforms