gpt4 book ai didi

ASP.NET 回发在使用带有 PathInfo 的 URL 时不起作用

转载 作者:行者123 更新时间:2023-12-04 07:04:49 25 4
gpt4 key购买 nike

我正在用 ASP.NET 3.5† 编写一个网站,在这个阶段我的大部分 URL 都使用 PathInfo,如下所示:

http://localhost:<whatever>/Account.aspx/Login

唯一的问题是,当表单回发时,它会尝试使用 URL:
http://localhost:<whatever>/Account.aspx/Account.aspx

到目前为止,我已经尝试设置 PostbackURL按钮的属性为 ~/Account.aspx ,但同样的事情发生了。

我也试过发布到一个单独的 DoLogin.aspx页面,但表单变量不会随它一起发送。

我真的不想在 Session 集合中设置用户名和密码。

谢谢。

† 我会使用 MVC,但我无法让它与我的主机一起正常工作。

最佳答案

这些文章提供了解决方法,可以满足您的需求。

http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
http://blogs.iis.net/ruslany/archive/2008/10/23/asp-net-postbacks-and-url-rewriting.aspx

我相信您的问题与影响使用 URL 重写的任何人的问题相同。尽管这些方法非常不同,但它们都会导致页面位置与系统认为页面位置之间的不匹配。

快速问题 - 您是否有机会使用 3.5 SP1?
如果是这样,您可以手动设置表单操作 - 基本上类似于

<form ID="ImAForm" action="~/Account.aspx" runat="server> 

不幸的是,我无法确定这是否是相同的问题。从逻辑上讲,它似乎确实是同一个问题,但我找不到任何特定于 pathInfo 的内容,而且我的大部分经验都与 URL 重写有关。如果您没有 SP1,则无法轻松覆盖表单操作,因此接下来要尝试的是第一个博客中引用的方法...

这是文章的相关部分......

Handling ASP.NET PostBacks with URL Rewriting

One gotcha that people often run into when using ASP.NET and Url-Rewriting has to-do with handling postback scenarios. Specifically, when you place a control on a page, ASP.NET will automatically by default output the "action" attribute of the markup to point back to the page it is on. The problem when using URL-Rewriting is that the URL that the control renders is not the original URL of the request (for example: /products/books), but rather the re-written one (for example: /products.aspx?category=books). This means that when you do a postback to the server, the URL will not be your nice clean one.

With ASP.NET 1.0 and 1.1, people often resorted to sub-classing the control and created their own control that correctly output the action to use. While this works, it ends up being a little messy - since it means you have to update all of your pages to use this alternate form control, and it can sometimes have problems with the Visual Studio WYSIWYG designer.

The good news is that with ASP.NET 2.0, there is a cleaner trick that you can use to rewrite the "action" attribute on the control. Specifically, you can take advantage of the new ASP.NET 2.0 Control Adapter extensibility architecture to customize the rendering of the control, and override its "action" attribute value with a value you provide. This doesn't require you to change any code in your .aspx pages. Instead, just add a .browser file to your /app_browsers folder that registers a Control Adapter class to use to output the new "action" attribute:



希望有所帮助 - 抱歉,我在最初的帖子中没有说清楚。
如果这不起作用,请告诉我...

关于ASP.NET 回发在使用带有 PathInfo 的 URL 时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1271614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com