简体   繁体   English

Asp.net URL在回发时丢失页面路径

[英]Asp.net Url loses page path on postback

Background: We are redoing our website and trying to modernize it. 背景:我们正在重做我们的网站并尝试对其进行现代化。 We were initially experimenting with AngularJS but dropped it due to some of our users being on unsupported browsers. 我们最初使用AngularJS进行实验,但由于某些用户使用不受支持的浏览器而将其删除。 We ended up just doing VB webforms and updating the design and functionality of our site. 我们最终只是制作VB网络表单并更新了网站的设计和功能。

I was having an issue with buttons or items that cause a postback. 我遇到导致回发的按钮或项目的问题。 When the page tries to postback it hits to the path but loses everything between the hostname and the last "/" 当页面尝试回发时,它会到达路径,但会丢失主机名和最后一个“ /”之间的所有内容

For example I have a login page set up in the location /Secure/Account/Login.aspx 例如,我在/Secure/Account/Login.aspx位置设置了一个登录页面。

I have a route as well that directs from /Secure/Account/Login. 我也有一条从/ Secure / Account / Login出发的路线。

So when you visit the page you are at: www.website.com/Secure/Accounts/Login 因此,当您访问该页面时,您将位于:www.website.com/Secure/Accounts/Login

When I click the login button though, instead of posting back, I am directed to: www.website.com/Login which doesn't exist so I get an error. 但是,当我单击登录按钮时,而不是回发,我被定向到:www.website.com/Login,该地址不存在,所以出现错误。

This occurs if I navigate to the page instead of using the route as well. 如果我导航到页面而不是使用路线,则会发生这种情况。 So if I am at www.website.com/Secure/Accounts/Login.aspx and click the button, I end up on www.website.com/Login.aspx with an error. 因此,如果我在www.website.com/Secure/Accounts/Login.aspx上并单击该按钮,那么我最终在www.website.com/Login.aspx上会出现错误。

This doesn't affect pages in the root directory as long as they do not use routing attributes. 只要不使用路由属性,这就不会影响根目录中的页面。 We have some pages that use routing attributes that have the same issue though. 但是,有些页面使用的路由属性存在相同的问题。

We have page /Category.aspx in the root directory with the route /Category/{Attribute1}/{Attribute2}/ configured for the page. 我们在根目录中有页面/Category.aspx,并为页面配置了路由/ Category / {Attribute1} / {Attribute2} /。

If I am on the page www.website.com/Category/Attribute1/Attribute2 when I click on a button that posts back, I end up at www.website.com/Attribute2 with an error. 如果在单击回发按钮时位于www.website.com/Category/Attribute1/Attribute2页面上,则我在www.website.com/Attribute2处出现错误。

The issue ended up being a really small piece of code from when we were working with Angular 从我们使用Angular以来,这个问题最终只是一小段代码

On our master page .aspx we had included the line: 在我们的.aspx主页上,我们添加了以下行:

<base href="/">

Removing this line, which we didn't even need anymore fixed the issue. 删除此行,我们甚至不需要此行,从而解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM