使用上下文重写路径时获取对象引用

时间:2009-09-27 21:27:22

标签: c# nullreferenceexception identify

我在代码隐藏中遇到此错误时收到此错误:if(Page.User.Identity.IsAuthenticated)

  System.NullReferenceException: Object reference not set to an instance of an object.

当我使用context.RewritePath方法时显示此错误 http://localhost/page.apsx?id=22 - > http://localhost/hello-world/

Page.User.Identity.IsAuthenticated返回True,当我去page.aspx?id = 22但我得到

  System.NullReferenceException: Object reference not set to an instance of an object.
当我去/ hello-world / url时出现

错误。

1 个答案:

答案 0 :(得分:0)

如果url.Contains(“List”)然后重写这样的url:

context.RewritePath(Utility.WebRoot + "List/Add.aspx", false);

我的重写者并没有那么复杂。