MVC 2如何在不重定向的情况下访问url?

发布于 2024-11-11 14:25:47 字数 82 浏览 3 评论 0原文

有没有一种方法可以访问某个网址而不重定向到该网址?基本上我想在后台从我的应用程序中调用一个网址,以便它可以注销依赖方。

感谢您的帮助。

Is there a way to go to a url without redirecting to it? Basically I want to call a url from within my application in the background so it can logout a reliant party.

Appreciate the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

帅气尐潴 2024-11-18 14:25:47

您尝试执行的操作不会要求我们回答,因为它与您自己的身份验证实施直接相关。

基于表单身份验证的普通 ASP.NET 身份验证,您将需要始终从浏览器获取 URL,因为它依赖于给定的身份验证。

您可以通过打开您的网站并登录来尝试一下,然后,在您的应用程序网址中打开其他浏览器品牌(不是浏览器窗口)...您会发现您还 >需要再次登录,因为身份验证已连接到第一个浏览器。

作为应用程序架构师,您可以通过实现另一种身份验证方式来实现这一点,通常在这种情况下,这种情况发生在使用需要身份验证代码的 Web 服务时 > 首先(通过调用 Login 方法给出),并且始终需要将该代码附加到对系统的任何调用的正文或标头

这样您就可以轻松删除身份验证代码,并且所有过程调用都将失败。

如前所述,这不取决于我们,而是由您来创建正确的身份验证层


从您的评论来看,

这就像使用 WebClient 对象一样简单

 WebClient client = new WebClient ();
 string reply = client.DownloadString (address);

What you are trying to do does not compete us to answer as it's directly related to your own Authentication implementation.

A normal ASP.NET Authentication based in Forms Authentication you will need always to lunch the url from a browser as it is there that relies the Authentication given.

You can give yourself a try by opening your website and log in into it, after that, open other browser brand (not browser window) into your application url... you will see that you also need to login again as the Authentication is hook up into the first browser.

It's Up to you as Application Architect to make this by implementing another way of authentication, normally in this kind'a cases, this happend when consuming web services where you need a authentication code first (given by calling a Login method) and that code is always needed to be appended to the body or header of any call to the system.

This way you can easily remove the authentication code and all procedure calls will fail.

As said, this is not up to us, it's up to you to create the correct Authentication Layer.


from your comment

it's as simple as using WebClient object

 WebClient client = new WebClient ();
 string reply = client.DownloadString (address);
坚持沉默 2024-11-18 14:25:47

如果您希望转移到新的 url 请求,您仍然可以使用。

Server.TransferRequest()

这样做的问题是,如果不使用重定向,浏览器地址栏将不会反映您已将其请求转移到另一个 URL 的事实。

If you wish to transfer to a new url request you can still use

Server.TransferRequest()

The problem with this is that by not using a redirect the browsers address bar will not reflect the fact that you have moved their request to another URL.

心欲静而疯不止 2024-11-18 14:25:47

要让客户端在后台访问给定的 URL,您应该对其进行 AJAX 调用,或者可能使用带有注销 url 的 src 的图像(尽管您必须确保也返回图像的 FileResult) )。这就是大多数分析包在后台调用其相关 URL 的方式。

但这里的问题是,这两种方法都不是 100% 可靠,关闭浏览器上的 JavaScript 或图像,这些结果就会失败。

根据您所说的,我认为您所追求的是让用户继续访问各种页面中的任何一个,而不是特定的注销页面。如果确实如此,您最好的解决方案实际上是双重重定向。

让您的应用程序重定向到您的注销 URL,但事先将您希望它们访问的页面的 URL 放入 tempdata 中。然后,在注销页面的操作结果中,您可以根据需要进行注销,并从 tempdata 返回到 url 的重定向。

To have the client visit a given URL in the background you should either make an AJAX call to it or possibly have an image with an src of your logout url (though you'd have to make sure that you return a FileResult of your image too). This is how most analytics packages call to their relevant urls in the background.

The problem here though is that neither is 100% reliable, turn off javascript or images on your browser and these results fail.

From what you've said I think what you're after is for a user to continue to any of a variety of pages rather than a specific logout page. If this is indeed the case your best solution is in fact a double redirect.

Have your application redirect to your logout url but before hand put the url of the page you want them to go to into tempdata. Then in the actionresult for the logout page you can do your logging out as required and return a redirect to the url from tempdata.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文