| Author |
Message |
Miles Thompson
Guest
|
Posted:
Thu Oct 06, 2005 8:51 am Post subject:
WebAuthorContext.Current.Mode NullReferenceException |
|
|
I have teh following code...
if (WebAuthorContext.Current!=null) {
Response.Redirect( WebAuthorContext.Current.GetUrlForMode(redirectToMe,
WebAuthorContext.Current.Mode));
}
Its throwing a null reference exception:
[NullReferenceException: Object reference not set to an instance of an
object.]
Microsoft.ContentManagement.WebControls.WebAuthorContext.EvaluateUnpublishedOrUpdateMode()
+491
Microsoft.ContentManagement.WebControls.WebAuthorContext.EvaluateMode()
+47
Microsoft.ContentManagement.WebControls.WebAuthorContext.get_Mode()
+15
<snip> in MyCode.aspx.cs:75
OK. Fair enough. But the Null reference exception is *not* that
"Response" or "WebAuthorContext.Current" or even "redirectToMe" is
null..
Rather, the *property* "Mode" of WebAuthorContext.Current is throwing a
null pointer exception just because I asked for its value. Note, the
problem is not that Mode is null, but rather that it throws an
exception when I look at it funny.
How can this be? Surely it is incorrect for one to have to deal with
such weird state exceptions across the API boundary?
--
Anyway... my problem now, is how do I avoid this null reference
exception.
I think (from trial and error) that this only happens when I'm in
update mode.. ie WBCMODE=AuthoringReedit or &WBCMODE=AuthoringNew but
I'm not at all sure how one detects that *before* asking it what the
WebAuthorContext.Current.Mode is?
--
Note that MyCode.aspx.cs is running as a script url on a channel and
this only hapepns if I click on that channelf rom a page that is
already in update mode.
I can post full code if desired. |
|
| Back to top |
|
 |
Stefan [MSFT]
Guest
|
Posted:
Thu Oct 06, 2005 12:50 pm Post subject:
Re: WebAuthorContext.Current.Mode NullReferenceException |
|
|
Hi Miles,
please post full code (but strip it down to the really required lines) to
let me do a repro.
Cheers,
Stefan
--
This posting is provided "AS IS" with no warranties, and confers no rights
New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
----------------------
"Miles Thompson" <utunga@gmail.com> wrote in message
news:1128577865.341827.155910@z14g2000cwz.googlegroups.com...
| Quote: | I have teh following code...
if (WebAuthorContext.Current!=null) {
Response.Redirect( WebAuthorContext.Current.GetUrlForMode(redirectToMe,
WebAuthorContext.Current.Mode));
}
Its throwing a null reference exception:
[NullReferenceException: Object reference not set to an instance of an
object.]
Microsoft.ContentManagement.WebControls.WebAuthorContext.EvaluateUnpublishedOrUpdateMode()
+491
Microsoft.ContentManagement.WebControls.WebAuthorContext.EvaluateMode()
+47
Microsoft.ContentManagement.WebControls.WebAuthorContext.get_Mode()
+15
snip> in MyCode.aspx.cs:75
OK. Fair enough. But the Null reference exception is *not* that
"Response" or "WebAuthorContext.Current" or even "redirectToMe" is
null..
Rather, the *property* "Mode" of WebAuthorContext.Current is throwing a
null pointer exception just because I asked for its value. Note, the
problem is not that Mode is null, but rather that it throws an
exception when I look at it funny.
How can this be? Surely it is incorrect for one to have to deal with
such weird state exceptions across the API boundary?
--
Anyway... my problem now, is how do I avoid this null reference
exception.
I think (from trial and error) that this only happens when I'm in
update mode.. ie WBCMODE=AuthoringReedit or &WBCMODE=AuthoringNew but
I'm not at all sure how one detects that *before* asking it what the
WebAuthorContext.Current.Mode is?
--
Note that MyCode.aspx.cs is running as a script url on a channel and
this only hapepns if I click on that channelf rom a page that is
already in update mode.
I can post full code if desired.
|
|
|
| Back to top |
|
 |
Miles Thompson
Guest
|
Posted:
Tue Oct 11, 2005 12:50 am Post subject:
Re: WebAuthorContext.Current.Mode NullReferenceException |
|
|
OK here's the full code.
Note that RedirectCorpHome.aspx.cs is code behind for an aspx page with
nothing on it. RedirectCorpHome.aspx is set as the "script URL" for a
set of specified channels.
The error occurs when a user is in AuthoringReEdit mode on a
*different* page and then they click on a link that takes them to the
channel in question.
I decided to skip posting that generates the link that takes the user
to the "channel in question" (and thence into this script URL). Suffice
it to say that the link that the user clicks on looks like this..
https://www.staging.domain.com/NR/exeres/DB84C04E-4CF3-471D-A65C-FA81DC03A43E.htm?NRMODE=Unpublished&WBCMODE=AuthoringReedit
The guid - DB84C04E-4CF3-471D-A65C-FA81DC03A43E - refers to a channel
not a posting. (I'm basically sure). Presumably, at some point in the
processing of a click on this link, it sees the Script URL property,
and then dives into the following code..
(Indenting as well as lots of other stuff has been edited to make this
code suitable for posting in email, but this is basically the gist of
it.)
RedirectCorpHome.aspx.cs
namespace Domain.CMS.WebForms
{
public class RedirectCorpHome : System.Web.UI.Page
{
private string [] namesToAvoid = {"archive", "taggerwindow"};
private void Page_Load(object sender, System.EventArgs e)
{
PostingCollection postings = CmsHttpContext.Current.Channel.Postings;
Posting redirectToMe =null;
postings.SortByOrdinal();
foreach (Posting posting in postings)
{
//<snip>
// I've removed code that basically finds the first
// posting with a template name that matches
// a certain pattern..
//</snip>
redirectToMe = posting;
}
if (redirectToMe == null)
{
redirectToMe = postings[0];
}
if (redirectToMe == null)
{
Response.Redirect( "/");
}
try
{
Response.Redirect(
WebAuthorContext.Current.GetUrlForMode( redirectToMe,
WebAuthorContext.Current.Mode));
}
catch(NullReferenceException ex)
{
// Right here is where we got a problem!!
//<snip>
}
Response.Redirect("/");
}
}
#region Web Form Designer generated code
#endregion
}
}
Stefan [MSFT] wrote:
| Quote: | Hi Miles,
please post full code (but strip it down to the really required lines) to
let me do a repro.
Cheers,
Stefan
--
This posting is provided "AS IS" with no warranties, and confers no rights
New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
----------------------
"Miles Thompson" <utunga@gmail.com> wrote in message
news:1128577865.341827.155910@z14g2000cwz.googlegroups.com...
I have teh following code...
if (WebAuthorContext.Current!=null) {
Response.Redirect( WebAuthorContext.Current.GetUrlForMode(redirectToMe,
WebAuthorContext.Current.Mode));
}
Its throwing a null reference exception:
[NullReferenceException: Object reference not set to an instance of an
object.]
Microsoft.ContentManagement.WebControls.WebAuthorContext.EvaluateUnpublishedOrUpdateMode()
+491
Microsoft.ContentManagement.WebControls.WebAuthorContext.EvaluateMode()
+47
Microsoft.ContentManagement.WebControls.WebAuthorContext.get_Mode()
+15
snip> in MyCode.aspx.cs:75
OK. Fair enough. But the Null reference exception is *not* that
"Response" or "WebAuthorContext.Current" or even "redirectToMe" is
null..
Rather, the *property* "Mode" of WebAuthorContext.Current is throwing a
null pointer exception just because I asked for its value. Note, the
problem is not that Mode is null, but rather that it throws an
exception when I look at it funny.
How can this be? Surely it is incorrect for one to have to deal with
such weird state exceptions across the API boundary?
--
Anyway... my problem now, is how do I avoid this null reference
exception.
I think (from trial and error) that this only happens when I'm in
update mode.. ie WBCMODE=AuthoringReedit or &WBCMODE=AuthoringNew but
I'm not at all sure how one detects that *before* asking it what the
WebAuthorContext.Current.Mode is?
--
Note that MyCode.aspx.cs is running as a script url on a channel and
this only hapepns if I click on that channelf rom a page that is
already in update mode.
I can post full code if desired.
|
|
|
| Back to top |
|
 |
Stefan [MSFT]
Guest
|
Posted:
Wed Oct 12, 2005 4:51 pm Post subject:
Re: WebAuthorContext.Current.Mode NullReferenceException |
|
|
Hi Miles,
I would suggest to change the redirect code as follows below.
As you are not changing the mode this should do the job:
Response.Redirect(redirectToMe.Url);
Cheers,
Stefan
--
This posting is provided "AS IS" with no warranties, and confers no rights
New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
----------------------
"Miles Thompson" <utunga@gmail.com> wrote in message
news:1128979250.182011.114110@g49g2000cwa.googlegroups.com...
[quote]OK here's the full code.
Note that RedirectCorpHome.aspx.cs is code behind for an aspx page with
nothing on it. RedirectCorpHome.aspx is set as the "script URL" for a
set of specified channels.
The error occurs when a user is in AuthoringReEdit mode on a
*different* page and then they click on a link that takes them to the
channel in question.
I decided to skip posting that generates the link that takes the user
to the "channel in question" (and thence into this script URL). Suffice
it to say that the link that the user clicks on looks like this..
https://www.staging.domain.com/NR/exeres/DB84C04E-4CF3-471D-A65C-FA81DC03A43E.htm?NRMODE=Unpublished&WBCMODE=AuthoringReedit
The guid - DB84C04E-4CF3-471D-A65C-FA81DC03A43E - refers to a channel
not a posting. (I'm basically sure). Presumably, at some point in the
processing of a click on this link, it sees the Script URL property,
and then dives into the following code..
(Indenting as well as lots of other stuff has been edited to make this
code suitable for posting in email, but this is basically the gist of
it.)
RedirectCorpHome.aspx.cs
namespace Domain.CMS.WebForms
{
public class RedirectCorpHome : System.Web.UI.Page
{
private string [] namesToAvoid = {"archive", "taggerwindow"};
private void Page_Load(object sender, System.EventArgs e)
{
PostingCollection postings = CmsHttpContext.Current.Channel.Postings;
Posting redirectToMe =null;
postings.SortByOrdinal();
foreach (Posting posting in postings)
{
//<snip
// I've removed code that basically finds the first
// posting with a template name that matches
// a certain pattern..
//</snip
redirectToMe = posting;
}
if (redirectToMe == null)
{
redirectToMe = postings[0];
}
if (redirectToMe == null)
{
Response.Redirect( "/");
}
try
{
Response.Redirect(
WebAuthorContext.Current.GetUrlForMode( redirectToMe,
WebAuthorContext.Current.Mode));
}
catch(NullReferenceException ex)
{
// Right here is where we got a problem!!
//<snip
}
Response.Redirect("/");
}
}
#region Web Form Designer generated code
#endregion
}
}
Stefan [MSFT] wrote:
Hi Miles,
please post full code (but strip it down to the really required lines) to
let me do a repro.
Cheers,
Stefan
--
This posting is provided "AS IS" with no warranties, and confers no
rights
New to MCMS?
Check out this book: Building Websites Using MCMS:
http://tinyurl.com/6zj44
----------------------
"Miles Thompson" <utunga@gmail.com> wrote in message
news:1128577865.341827.155910@z14g2000cwz.googlegroups.com...
I have teh following code...
if (WebAuthorContext.Current!=null) {
Response.Redirect( WebAuthorContext.Current.GetUrlForMode(redirectToMe,
WebAuthorContext.Current.Mode));
}
Its throwing a null reference exception:
[NullReferenceException: Object reference not set to an instance of an
object.]
Microsoft.ContentManagement.WebControls.WebAuthorContext.EvaluateUnpublishedOrUpdateMode()
+491
Microsoft.ContentManagement.WebControls.WebAuthorContext.EvaluateMode()
+47
Microsoft.ContentManagement.WebControls.WebAuthorContext.get_Mode()
+15
snip> in MyCode.aspx.cs:75
OK. Fair enough. But the Null reference exception is *not* that
"Response" or "WebAuthorContext.Current" or even "redirectToMe" is
null..
Rather, the *property* "Mode" of WebAuthorContext.Current is throwing a
null pointer exception just because I asked for its value. Note, the
problem is not that Mode is null, but rather that it throws an
exception when I look at it funny.
How can this be? Surely it is incorrect for one to have to deal with
such weird state exceptions across the API boundary?
--
Anyway... my problem now, is how do I avoid this null reference
exception.
I think (from trial and error) that this only happens when I'm in
update mode.. ie WBCMODE=AuthoringReedit or &WBCMODE=AuthoringNew but
I'm not at all sure how one detects that *before* asking it what the
WebAuthorContext.Current.Mode is?
--
Note that MyCode.aspx.cs is running as a script url on a channel and
this only hapepns if I click on that channelf rom a page that is
already in update mode.
I can post full code if desired.
[/quote] |
|
| Back to top |
|
 |
Miles Thompson
Guest
|
Posted:
Tue Oct 18, 2005 12:50 pm Post subject:
Re: WebAuthorContext.Current.Mode NullReferenceException |
|
|
Stefan,
Thanks for that advice. For what its worth, thats actually how the code
used to read.. namely:
//NB: The url property preserves the current mode, unless that mode is
"update" which is
// the desired behaviour in this case
Response.Redirect( redirectToMe.Url);
However, when we did this, we got some pretty undesirable behaviour
when a user clicked on the left nav straight from AuthoringReEdit mode.
If they did this, the pop up would show 'Are you sure you want to do
this, you will lose all your unsaved content' (or somehting like that)
but if the user chose yes they would end up in a really weird state
where neither the DefaultConsole or the 'EditSiteConsoler' would be
visible.
By 'EditSiteConsole' I mean the 'switch to edit mode' thing..
<cms:PresentationModeContainer id="PresentationPublishedModeContainer"
runat="server" mode="Published">
<CmsConsole:SwitchToPresentationUnpublishedAction
id="SwitchToPresentationUnpublishedAction" runat="server">
....
<cms:PresentationModeContainer id="Presentationmodecontainer1"
runat="server" mode="UnPublished">
<CmsConsole:SwitchToPresentationPublishedAction
id="SwitchToPresentationPublishedAction" runat="server">
....
etc..
By DefaultConsole I mean the thing that you click to edit, approve,
submit, or save, save and exit etc a posting.
I am assuming that the EditSiteConsole wouldn't display because we were
still in an Update mode... but the DefaultConsole wouldn't display
becacuse there was no appropriate WBCMode parameter in the get string
(or something).
To be honest i don't know quite what the problem with 'just' using
posting.Url was but it wasn't working for us... maybe we are missing
somethign here???
In any event (in case someone else needs to know this) the code we have
now reads as follows
//NB: The aim here is preserve the current mode except when
// we are currently in &WBCMODE=AuthoringReedit, or
&WBCMODE=AuthoringNew in which case, just
// drop back to unpublished preview mode.
//arghh.. i'm just gonna catch the error condition for now, (till I
hear back)
// see http://tinyurl.com/a7zgr
// and http://blog.is.not/miles/archive/2005/10/06/321.aspx
try {
Response.Redirect(
WebAuthorContext.Current.GetUrlForMode(redirectToMe,
WebAuthorContext.Current.Mode));
}
catch (NullReferenceException)
{
Response.Redirect(
WebAuthorContext.Current.GetUrlForMode(redirectToMe,
WebAuthorContextMode.PresentationUnpublished, false));
}
It seems a bit like I must be doing something wrong to be catching an
Exception in the 'normal' flow of things but I guess if it works, it
works?
As I say, I wondered if you think I am missing something (ie I don't
want to be doing thigs the 'wrong' way) or maybe this is a reasonable
solution? |
|
| Back to top |
|
 |
Stefan [MSFT]
Guest
|
Posted:
Tue Oct 18, 2005 12:50 pm Post subject:
Re: WebAuthorContext.Current.Mode NullReferenceException |
|
|
Hi Miles,
that should not happen.
You should open a support case for this.
Cheers,
Stefan
--
This posting is provided "AS IS" with no warranties, and confers no rights
New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
----------------------
"Miles Thompson" <utunga@gmail.com> wrote in message
news:1129628740.670636.171810@g44g2000cwa.googlegroups.com...
| Quote: | Stefan,
Thanks for that advice. For what its worth, thats actually how the code
used to read.. namely:
//NB: The url property preserves the current mode, unless that mode is
"update" which is
// the desired behaviour in this case
Response.Redirect( redirectToMe.Url);
However, when we did this, we got some pretty undesirable behaviour
when a user clicked on the left nav straight from AuthoringReEdit mode.
If they did this, the pop up would show 'Are you sure you want to do
this, you will lose all your unsaved content' (or somehting like that)
but if the user chose yes they would end up in a really weird state
where neither the DefaultConsole or the 'EditSiteConsoler' would be
visible.
By 'EditSiteConsole' I mean the 'switch to edit mode' thing..
cms:PresentationModeContainer id="PresentationPublishedModeContainer"
runat="server" mode="Published"
CmsConsole:SwitchToPresentationUnpublishedAction
id="SwitchToPresentationUnpublishedAction" runat="server"
...
cms:PresentationModeContainer id="Presentationmodecontainer1"
runat="server" mode="UnPublished"
CmsConsole:SwitchToPresentationPublishedAction
id="SwitchToPresentationPublishedAction" runat="server"
...
etc..
By DefaultConsole I mean the thing that you click to edit, approve,
submit, or save, save and exit etc a posting.
I am assuming that the EditSiteConsole wouldn't display because we were
still in an Update mode... but the DefaultConsole wouldn't display
becacuse there was no appropriate WBCMode parameter in the get string
(or something).
To be honest i don't know quite what the problem with 'just' using
posting.Url was but it wasn't working for us... maybe we are missing
somethign here???
In any event (in case someone else needs to know this) the code we have
now reads as follows
//NB: The aim here is preserve the current mode except when
// we are currently in &WBCMODE=AuthoringReedit, or
&WBCMODE=AuthoringNew in which case, just
// drop back to unpublished preview mode.
//arghh.. i'm just gonna catch the error condition for now, (till I
hear back)
// see http://tinyurl.com/a7zgr
// and http://blog.is.not/miles/archive/2005/10/06/321.aspx
try {
Response.Redirect(
WebAuthorContext.Current.GetUrlForMode(redirectToMe,
WebAuthorContext.Current.Mode));
}
catch (NullReferenceException)
{
Response.Redirect(
WebAuthorContext.Current.GetUrlForMode(redirectToMe,
WebAuthorContextMode.PresentationUnpublished, false));
}
It seems a bit like I must be doing something wrong to be catching an
Exception in the 'normal' flow of things but I guess if it works, it
works?
As I say, I wondered if you think I am missing something (ie I don't
want to be doing thigs the 'wrong' way) or maybe this is a reasonable
solution?
|
|
|
| Back to top |
|
 |
|
|
|
|