jQuery PageMethods 401身份验证失败,并显示FriendlyUrls

编程入门 行业动态 更新时间:2024-10-07 12:25:48
本文介绍了jQuery PageMethods 401身份验证失败,并显示FriendlyUrls的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经将FriendlyUrls nuget包添加到了WebForm应用程序中.

I have FriendlyUrls nuget package added to WebForm application.

在RegisterRoutes中,我有:

In RegisterRoutes I have:

var settings = new FriendlyUrlSettings(); //settings.AutoRedirectMode = RedirectMode.Off; settings.AutoRedirectMode = RedirectMode.Permanent; routes.EnableFriendlyUrls(settings);

我创建了2页WebForm1.aspx和WebForm2.aspx

I created 2 pages WebForm1.aspx and WebForm2.aspx

在WebForm1.aspx上,我在头引用了jQuery v1.9.1,只是在主体的默认div标记内添加了以下内容:

On WebForm1.aspx I referenced jQuery v1.9.1 in the head simply added the following inside the default div tag in the body:

<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) ? "" : ""); 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保持标准状态,但在背后的代码中添加了一种方法:

WebForm2.aspx is kept stock standard after adding the file to the project, except for 1 method added to the code behind:

[System.Web.Services.WebMethod(EnableSession = false)] public static string GetCategories() { return "hi"; }

运行页面WebForm1.aspx时,得到以下结果:

When I run the page WebForm1.aspx I get the following result:

{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}

在提琴手中查看请求时,我可以看到友好的URL并未剥离.aspx扩展名(这是一件好事):

When view the request in fiddler I can see the friendly url did not strip the .aspx extension (which is a good thing):

localhost:14918/WebForm2.aspx/GetCategories

但是,如上所示,FriendlyUrlSettings将AutoRedirectMode设置为RedirectMode.Permanent,并且当您取消注释RedirectMode.Off的行并注释掉Permanent时,实际上您会在屏幕上得到结果"Hi".

However as shown above, the FriendlyUrlSettings has the AutoRedirectMode set to RedirectMode.Permanent and when you uncomment the line for RedirectMode.Off and comment the Permanent out, then you actually get the result "Hi" printed on the screen.

任何人都知道原因可能是什么,或如何在路由中添加排除项?

Anyone has any ideas what the cause could be or how to add an exclusion to the routes?

我已尝试遵循,但它似乎并不会以任何方式影响我不断获得的401结果:

I have tried to following but it does not seem to affect in any way the 401 result I keep getting:

//routes.Add(new Route("*Remote.aspx*", new StopRoutingHandler())); //routes.Ignore("{remote}", new { remote = @".*\Remote.aspx(/.)?" });

推荐答案

您刚刚保存了我的一天.下面是代码的C#版本.对于母版页,只需粘贴PageMethods.set_path("default.aspx")在关闭内容标签之前

You just saved my day.Below is the c# version of the code.In case of the master pages just paste PageMethods.set_path("default.aspx") before closing Content tag

public static void RegisterRoutes(RouteCollection routes) { var settings = new FriendlyUrlSettings(); settings.AutoRedirectMode = RedirectMode.Permanent; routes.EnableFriendlyUrls(settings, new CustomFriendlyUrlResolver()); } public class CustomFriendlyUrlResolver : WebFormsFriendlyUrlResolver { public override string ConvertToFriendlyUrl(string path) { if (HttpContext.Current.Request.PathInfo != "") { return path; } else { return base.ConvertToFriendlyUrl(path); } } }

更多推荐

jQuery PageMethods 401身份验证失败,并显示FriendlyUrls

本文发布于:2023-11-24 00:52:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623369.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   PageMethods   jQuery   FriendlyUrls

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!