错误日志——PreviousPage is null when attempting ...

在创建的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 ↩

你可能感兴趣的:(VisualStudio)