Asp.net URL在回发时丢失页面路径 [英] Asp.net Url loses page path on postback

查看:77
本文介绍了Asp.net URL在回发时丢失页面路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我们正在重做我们的网站,并试图对其进行现代化.我们最初使用AngularJS进行实验,但由于某些用户使用的浏览器不受支持而将其删除.我们最终只是制作了VB网络表单,并更新了网站的设计和功能.

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. We ended up just doing VB webforms and updating the design and functionality of our site.

我遇到导致回发的按钮或项目的问题.当页面尝试回发时,它会到达路径,但会丢失主机名和最后一个"/"之间的所有内容

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 "/"

例如,我在该位置设置了一个登录页面/Secure/Account/Login.aspx

For example I have a login page set up in the location /Secure/Account/Login.aspx

我也有一条从/Secure/Account/Login出发的路线.

I have a route as well that directs from /Secure/Account/Login.

因此,当您访问页面时,您位于:www.website.com/Secure/Accounts/Login

So when you visit the page you are at: www.website.com/Secure/Accounts/Login

但是,当我单击登录按钮时,我没有回发,而是被定向到:www.website.com/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/Secure/Accounts/Login.aspx上并单击该按钮,那么我最终在www.website.com/Login.aspx上会出现错误.

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.

这不会影响根目录中的页面,只要它们不使用路由属性即可.我们有一些页面使用了路由属性,但是存在相同的问题.

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.

我们在根目录中有/Category.aspx页面,其中包含路由/Category/{Attribute1}/{Attribute2}/为页面配置.

We have page /Category.aspx in the root directory with the route /Category/{Attribute1}/{Attribute2}/ configured for the page.

如果单击返回按钮时我在www.website.com/Category/Attribute1/Attribute2页面上,则我在www.website.com/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.

推荐答案

这个问题最终只是我们使用Angular时的一小段代码

The issue ended up being a really small piece of code from when we were working with Angular

在.aspx主页上,我们添加了以下行:

On our master page .aspx we had included the line:

<base href="/">

删除此行,我们甚至不需要此行.

Removing this line, which we didn't even need anymore fixed the issue.

这篇关于Asp.net URL在回发时丢失页面路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆