错误日志——PreviousPage is null when attempting a cross-page postback using a button and the PostBack

在创建的Web项目中尝试跨页面传值时,发现target page中PreviousPage总是空。
这意味着MY CROSS PAGE POSTING NOT WORKING,但是我确信所有的代码无误。
在查找原因后发现,在当前项目下创建的任何page(创建路径:文件->新建项目->模板->Visual C#->Web->ASP.NET Web 应用程序),启动调试在IE中都自动隐藏后缀(.aspx),至此原因找到。

When you use the default WebForm from visual Studio, the AutoRedirectMode is set to Permanent. This makes you request into a “GET” and since you are using Friendly URLs1, you can’t evaluate the PreviousPage.

The problem was the FriendlyUrls nuget package was removing the .aspx after my page names so my target page was not WebForm2.aspx but just WebForm2. This made the previous page null.

If you want a “POST” action then set the AutoRedirectMode = RedirectMode.Off (this will give you PreviousPage info but only from non-Friendly-Url pages [ex: www.you.com/mypage.aspx], however this will get you an error if you try to access the Friendly-Url page [ex: www.you.com/mypage] << no .aspx).

So What we should do is disable FriendlyUrls or create project in another path by 文件->新建项目->模板->Visual C#->Web->Visual Studio 2012->ASP.NET 空 Web 应用程序/ASP.NET Web 窗体应用程序。

至于为什么这么创建出来的项目不自动开启FriendlyUrls,此处并没有深究。


  1. ASP.NET Friendly URLs is a library for ASP.NET 4.5 Web Forms applications that enables developers to create URLs without file extensions for certain ASP.NET file types (such as .aspx and .ashx files). ——from MSDN
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值