Showing posts with label implemented. Show all posts
Showing posts with label implemented. Show all posts

Saturday, March 31, 2012

Strange behavior with HttpCookieCollection

Hi,

I created a simple webform, put a test button on it and implemented a
click handler that looks like so:

private void btnTest_Click(object sender, System.EventArgs e)
{
HttpCookieCollection oCookReq =
HttpContext.Current.Request.Cookies;
HttpCookieCollection oCookResp =
HttpContext.Current.Response.Cookies;

int n1 = oCookReq.Count;
int n2 = oCookResp.Count;
bool bIsNull = (oCookResp["someCookieName"] == null);
int n3 = oCookReq.Count;
int n4 = oCookResp.Count;

Response.Write(string.Format("Before: Request = {0}, Response
= {1}<br>", n1, n2));
Response.Write(string.Format("After: Request = {0}, Response
= {1}<br>", n3, n4));
}

When I click the button the test output on the page is:

Before: Request = 1, Response = 0
After: Request = 2, Response = 1

Can anyone explain why the mere act of looking for a cookie in the
response collection would cause one to get added to both the response
and request collections? I tried the test again using a new
HttpCookieCollection (i.e. not one from the current context) and do
not get this behavior. Clues?

Thanks much...

- Aadlaird@.earthlink.net wrote in
news:3f18afd7.184287250@.news.earthlink.net:

> Hi,
> I created a simple webform, put a test button on it and
> implemented a click handler that looks like so:
> private void btnTest_Click(object sender, System.EventArgs e)
> {
> HttpCookieCollection oCookReq =
> HttpContext.Current.Request.Cookies;
> HttpCookieCollection oCookResp =
> HttpContext.Current.Response.Cookies;
> int n1 = oCookReq.Count;
> int n2 = oCookResp.Count;
> bool bIsNull = (oCookResp["someCookieName"] == null);
> int n3 = oCookReq.Count;
> int n4 = oCookResp.Count;
> Response.Write(string.Format("Before: Request = {0},
> Response
>= {1}<br>", n1, n2));
> Response.Write(string.Format("After: Request = {0},
> Response
>= {1}<br>", n3, n4));
> }
>
> When I click the button the test output on the page is:
> Before: Request = 1, Response = 0
> After: Request = 2, Response = 1
> Can anyone explain why the mere act of looking for a cookie in
> the response collection would cause one to get added to both the
> response and request collections? I tried the test again using
> a new HttpCookieCollection (i.e. not one from the current
> context) and do not get this behavior. Clues?

You've stumbled upon a frustrating (and, AFAIK, undocumented) aspect
of the ASP.NET cookies response collection. Simply querying the
collection will create the cookie if it doesn't exist.

Here's an article that explains this in more depth:

http://www.codeproject.com/aspnet/AspNetCookies.asp

Hope this helps.

Chris.
----
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Saturday, March 24, 2012

Strange Errors...Don't Understand

I recently implemented error processing on my .net website, where I send
myself an email from global.asax on an application error. In the last two
days I have gotten a "The file '/detail.aspx' does not exits" type
error--with two different file names. In both cases, I searched my entire
source for the '/detail.aspx' reference and it doesn't exist.

What could be causing this error? Text of error email I sent to myself
follows...

The file '/detail.aspx' does not exist.

System.Web.HttpException: The file '/detail.aspx' does not exist. at
System.Web.UI.Util.CheckVirtualFileExists(VirtualP ath virtualPath) at
System.Web.Compilation.BuildManager.GetVPathBuildR esultInternal(VirtualPath
virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean
allowBuildInPrecompile) at
System.Web.Compilation.BuildManager.GetVPathBuildR esultWithNoAssert(HttpContext
context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp,
Boolean allowBuildInPrecompile) at
System.Web.Compilation.BuildManager.GetVirtualPath ObjectFactory(VirtualPath
virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) at
System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) at
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context, String
requestType, VirtualPath virtualPath, String physicalPath) at
System.Web.UI.PageHandlerFactory.System.Web.IHttpH andlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath) at
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at
System.Web.HttpApplication.MapHandlerExecutionStep .System.Web.HttpApplication.IExecutionStep.Execute ()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)See if this helps :

http://www.velocityreviews.com/foru...-aspnet-20.html
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"Paul Buzza, oldster using new tools" <PaulBuzzaoldsterusingnewtools@.discussions.microsof t.comwrote in message
news:9550498C-9323-4D8A-BA54-555CCFE19734@.microsoft.com...

Quote:

Originally Posted by

>I recently implemented error processing on my .net website, where I send
myself an email from global.asax on an application error. In the last two
days I have gotten a "The file '/detail.aspx' does not exits" type
error--with two different file names. In both cases, I searched my entire
source for the '/detail.aspx' reference and it doesn't exist.
>
What could be causing this error? Text of error email I sent to myself
follows...
>
The file '/detail.aspx' does not exist.
>
System.Web.HttpException: The file '/detail.aspx' does not exist. at
System.Web.UI.Util.CheckVirtualFileExists(VirtualP ath virtualPath) at
System.Web.Compilation.BuildManager.GetVPathBuildR esultInternal(VirtualPath
virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean
allowBuildInPrecompile) at
System.Web.Compilation.BuildManager.GetVPathBuildR esultWithNoAssert(HttpContext
context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp,
Boolean allowBuildInPrecompile) at
System.Web.Compilation.BuildManager.GetVirtualPath ObjectFactory(VirtualPath
virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) at
System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) at
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context, String
requestType, VirtualPath virtualPath, String physicalPath) at
System.Web.UI.PageHandlerFactory.System.Web.IHttpH andlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath) at
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at
System.Web.HttpApplication.MapHandlerExecutionStep .System.Web.HttpApplication.IExecutionStep.Execute ()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)


Juan,

Thank you. It was the "click" I needed. My old version of my site had the
named files on which I see the errors. If someone had a saved bookmark to
one of my old pages, this is the error I see. All I have to do is handle the
404 error with a separate error page, and tell the originator to update their
bookmarks.

Paul

"Juan T. Llibre" wrote:

Quote:

Originally Posted by

See if this helps :
>
http://www.velocityreviews.com/foru...-aspnet-20.html
>
>
>
>
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
======================================
"Paul Buzza, oldster using new tools" <PaulBuzzaoldsterusingnewtools@.discussions.microsof t.comwrote in message
news:9550498C-9323-4D8A-BA54-555CCFE19734@.microsoft.com...

Quote:

Originally Posted by

I recently implemented error processing on my .net website, where I send
myself an email from global.asax on an application error. In the last two
days I have gotten a "The file '/detail.aspx' does not exits" type
error--with two different file names. In both cases, I searched my entire
source for the '/detail.aspx' reference and it doesn't exist.

What could be causing this error? Text of error email I sent to myself
follows...

The file '/detail.aspx' does not exist.

System.Web.HttpException: The file '/detail.aspx' does not exist. at
System.Web.UI.Util.CheckVirtualFileExists(VirtualP ath virtualPath) at
System.Web.Compilation.BuildManager.GetVPathBuildR esultInternal(VirtualPath
virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean
allowBuildInPrecompile) at
System.Web.Compilation.BuildManager.GetVPathBuildR esultWithNoAssert(HttpContext
context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp,
Boolean allowBuildInPrecompile) at
System.Web.Compilation.BuildManager.GetVirtualPath ObjectFactory(VirtualPath
virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) at
System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert) at
System.Web.UI.PageHandlerFactory.GetHandlerHelper( HttpContext context, String
requestType, VirtualPath virtualPath, String physicalPath) at
System.Web.UI.PageHandlerFactory.System.Web.IHttpH andlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath) at
System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at
System.Web.HttpApplication.MapHandlerExecutionStep .System.Web.HttpApplication.IExecutionStep.Execute ()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)


>
>
>