Showing posts with label serious. Show all posts
Showing posts with label serious. Show all posts

Thursday, March 22, 2012

Serious and stupid problem..

Hi.

I'm using ASP.NET 1 .1 with C#..

My problem is very weird..I have a listbox and a button ,both are WebControls..

When I clicked on an item in Listbox code fires ListBox_SelectedItemChanged event and navigates to a new page. Until this part it works fine.

When I goto back by browsers BACK button anc click the Button ListBox_SelectedItemChanged fires again.Strange isn' t it??

Has anyone had this problem before?

I have checked the event handlar declarations and they are correct.

tguclu,

It is not strange behaviour. If you use BACK button , the page view comes from IE history. When you do a postback this page ( Buton click..etc..) ,SelectedItemChangedevent will fire because there is a change in index after intial load.

To avoid the problem, you can try this..

In page_Load..

if (!IsPostBack)

{

//***** Reset the Listbox selected index *********

MyListBox.SelectedIndex= 0;

}

Serious Bug: FormsAuthentication over Intranet MS Listen Up!!

I have been wrestling with FormsAuthentication working on some, but not all, of my development
websites. I think I've determined what is causing the problem, but I can't figure out the
workaround/solution to use in the VS.NET environment.

Background: I recently changed my development environment so that, instead of having access to only
one website at a time on my WinXP development machine I now "host" the sites on a backend Win2K
server. This is all on an intranet; no traversal of the public internet takes place.

To differentiate among the different sites I use multihoming, with each site getting a unique IP
address in the 192.168.1.xxx range. I should point out that the same problem whose "solution" I
describe here also occurred when I was >>not<< using multihoming, but different host header names
instead.

After making that switch, and transitioning the development sites to the Win2K server, I found that
certain Forms Authentication setups that had been running well for months suddenly stopped working.

I confirmed this problem in a stripped-down test application that has only two forms, one a login
form and one an empty form in a protected subdirectory of the site. No real authentication is done;
clicking on the Submit button of the login from simply calls:

FormsAuthentication.RedirectFromLoginPage("user1", true);

Note that this call sets up, or should set up, a persistent cookie.

Only it doesn't. No cookie at all is created, and so the user gets continually bounced back to the
login form.

After researching this for hours on google groups and msdn I came across an old MSDN article
entitled Internet Explorer Drops Site Server Cookie for Intranet Site IP Address (279186). The
article, which dates back to 2002, talks about a problem that can be cured by using the numeric IP
address for an intranet site, rather than its human-readable name.

In desperation I tried (outside of VS.NET) accessing the site with a numeric IP...and the cookie was
created! Authentication succeeded, and I was able to see the protected page.

Accessing the site using the human readable name continued to fail outside of VS.NET, as it had
inside of the development environment.

This problem seems to me to be very serious, in that how the heck can a developer "host" multiple
projects on an intranet that use FormsAuthentication if some of them succeed and some of them
fail?

I anxiously await feedback from Microsoft on how to fix this stupid problem.

- MarkHi,

Its far from being a solution but i just wonder way are you using
multihoming in intranet solution. I use to host about 60 application on
single site (single IP) that use
FormsAuthentication without any problems.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Ignorance? :)

Actually, I'm open to suggestion as to how best to handle multiple development sites simultaneously.
I'm currently trying multihoming, but I've also tried the host header approach (I encountered the
same problem, BTW).

What do you do/recommend?

- Mark
Mark,

This is not a bug actually. As per the W3C, when searching the cookie list
for valid cookies, a comparison of the domain attributes of the cookie is
made with the Internet domain name of the host from which the URL will be
fetched. If there is a tail match, then the cookie will go through path
matching to see if it should be sent. "Tail matching" means that domain
attribute is matched against the tail of the fully qualified domain name of
the host. A domain attribute of "matlus.com" would match host names
"delphi.matlus.com" as well as "delphi.isapi.matlus.com".
Only hosts within the specified domain can set a cookie for a domain and
domains must have at least two (2) or three (3) periods in them to prevent
domains of the form: ".com", ".edu", and "va.us". Any domain that fails
within one of the seven special top-level domains listed below only require
two periods. Any other domain requires at least three. The seven special top
level domains are: "COM", "EDU", "NET", "ORG", "GOV", "MIL", and "INT". The
default value of domain is the host name of the server, which generated the
cookie response.

--
Shiv R. Kumar
http://www.matlus.com
Hi Mark,

I'm sorry for keeping you waiting on the former post. I'm now assisting you
on it. Please feel free to followup in the former thread. As for the
question you mentioned in this one:
"how best to handle multiple development sites simultaneously"

In VS.NET there is a "CopyProject" function for you to copy an ASP.NET web
application from one place to another. You can try it via select the
"Project-->Copy Project..." menu. In the popup setting dialog, speciy a
destination position(using web url). Then, the VS.NET will help you to copy
the current web project to the specified place. Please try it out to see
whether it helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi,

I dont see any need to use multiple sites on the same machine in
intranet situation. Usually this technique used by ISP that needs to
serve different sites with different IP's. This is certainly not the
case while developing intranet applications. you can host all your
applications in single site.

There are also situations where single application demand heavy network
traffic and to minimize that application impact on other application you
might set it to different IP with different network card.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
This is certainly not the
> case while developing intranet applications. you can host all your
> applications in single site.

Provided you don't use global.asax in any form and your web.config file has
no special settings required by any of the applications.

--
Shiv R. Kumar
http://www.matlus.com
Why ?
Every application run in its own application domain and got its own
global.asax and web.config .

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Natty,

I've found that if I don't treat separate development projects (which will ultimately end up as
different websites, for different clients) as separate sites I run into problems like not being able
to resolve local addresses through MapPath() properly.

You may have misunderstood what I was getting at when I said "intranet". These projects will end up
running as separate, standalone websites once they are deployed. They don't all belong to the same
client.

I'm still interested in hearing what you do to develop separate projects for separate clients.

- Mark
Shiv,

I'm not sure I quite follow your argument, but if I'm understanding you, it still doesn't explain
why the site delivers the cookie when it is accessed as http://192.168.1.150 and fails to deliver
the cookie when it is accessed as http:://devproject1.arcabama.com, even though the DNS maps
192.168.1.150 to devproject1.arcabama.com. That's what my research shows as happening.

- Mark
Steven,

CopyProject wouldn't be appropriate in this particular case, because the test project I built (which
is exhibiting the problem) was built from the ground up on the Win2K server.

I'm interested in hearing an explanation as to why accessing a site via its numeric IP address
results in a cookie delivery while accessing it via its human-readable name fails to deliver a
cookie, even though the IP address and the name are mapped to each other in the DNS.

- Mark
Mark,

Ok, I didn't understand "human readable" to mean it was dotted :) I assumed
it to be a single machine name kind of situation rather than a domain name.

I know from experience you can't use, say localhost (even though localhost
maps to 127.0.0.1) in applications that use cookies (not just ASP.NET but
any kind) or netbois names. You have to use IP addresses in these situation.
I've not tried names like you use. I guess there must be something in the
cookie specification that talks to non routable IP addresses being mapped to
dotted domain names as well then (from a security point of view).

All I can say is this is not a bug IMHO :)
--
Shiv R. Kumar
http://www.matlus.com
Ah, but besides the fact that I think the behavior is pretty weird, the other reason I think it's a
bug is that it works on some of the intranet sites and not others... :)

- Mark

On Tue, 13 Jan 2004 13:15:23 -0500, "Shiv Kumar" <shivk@.erolsnoooospaaaam.com> wrote:

>Mark,
>Ok, I didn't understand "human readable" to mean it was dotted :) I assumed
>it to be a single machine name kind of situation rather than a domain name.
>I know from experience you can't use, say localhost (even though localhost
>maps to 127.0.0.1) in applications that use cookies (not just ASP.NET but
>any kind) or netbois names. You have to use IP addresses in these situation.
>I've not tried names like you use. I guess there must be something in the
>cookie specification that talks to non routable IP addresses being mapped to
>dotted domain names as well then (from a security point of view).
>All I can say is this is not a bug IMHO :)
> Ah, but besides the fact that I think the behavior is pretty weird, the
other reason I think it's a
> bug is that it works on some of the intranet sites and not others... :)

Sure, it's probably a bug. The question is where? :) I'm sure you've been
there before. It work here but not there etc. Eventually, you see the cause
of the problem and it's not a bug in your dev tool or platform but a
configuration bug of some sort.

Happy bug hunting :)

--
Shiv R. Kumar
http://www.matlus.com
Hi Mark,

Thanks for your response. As you mentioned that the "Copy Project" may be
unsuitable for your situation, would you please provide some further info
on your situation(such as the reason why the "CopyProject" unsuitable) so
that we can try to search for some other approachs. The "Copy Project"
function is independent of the operation system(whehter server or
workstation). Here is the relative description in MSDN:
http://msdn.microsoft.com/library/e...pyingproject.as
p?frame=true

In addition, you've mentioned another problem that "cookie delivery"
doesn't work in case of using the "domain name" address rather than the IP
address, does this problem occur within the same web application in the
former message(the particular test project)? would you please also provide
some more info on it so as for me to look for some relative materials to
assist you. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Steven,

The reason copy project is not appropriate is because I simply built the test project that's having
the problem, from scratch, on the server.

And yes, the built-from-scratch test project is experiencing the same problem.

- Mark
Hi Mark,

Thank you for the response. Regarding on the issue, we are
finding proper resource to assist you and we will update as soon as posible.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Have you checked the MSDN knownledge article 313116?

Eric
Hi Mark,

Based on your situation that you used the "multi-homed network
configuration" for FormAuthenticaion, I'd like to confirm something so as
for us to do further throublshoot on it. Would you please check the
following items:

1. I think you may add an extra submit button to his logon page. Then add
code to the load event to add a test cookie and also write to the browser
the value of that cookie, if it exists. After he submits the page a couple
times, the cookie value should appear. If this works, then we know that
FormsAuthentication is likely to be the problem.

2. If the above test fails, we need to try another test. Would you please
try the same experiment with an *.ASP page placed in the same folder as the
..NET project that is failing. If the ASP page fails, then we know it's not
caused by .NET. If it works, then we know the problem is specific to .NET.

3.If the ASPX and ASP pages both fail, then try adding an HTML page and use
IIS settings to add a cookie header such as:
name: Set-Cookie
value: abc=testing; expires=Sat, 01-Jan-2050; path=/

Then after request the HTML page, you can look in the cookie folder on
your machine to see if you can got the cookie. If it works, then it's both
ASP and ASPX. If it fails, I'll look for other causes.

Please try out the preceding suggestions. And if you have any new findings
on this issue, please also let me know. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Steven,

I'll try your suggestions over the next few days, except for the one about trying an "old style" ASP
page. I don't know ASP, and don't intend to learn it just to debug something.

- Mark

Serious cache problem - Page_Load get never get called !

Hi,
I got a asp.net page that stores session variable.
This page gets input parameter by QueryString and this variable stored
into session variable.
Asp.net page works in normal navigation scenario.
Then I bookmarked this url to my favorites and call this url by
clicking favorites link.
When in this situation, at initial time Page_Load() of my asp.net gets
called but after first time, page never get called by clicking
favorites link.
I guess maybe IE caches the link and read it when user clicks from
favorite link.
I've tried below codes only to fail to call Page_Load(). All of them
failed.
Response.Expires = 0;
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
Navigating my asp.net pages by favorites link is very possible user
scenario.
This is unavoidable.
How can I always ensure IE to read URL from Web Server not from cache
when user clicks favorites link?
Any suggestion will be appreciated. TIA. :)
Regards,
RyanAppending the header doesn't necessarily tell the browser not to cache the
page. For that, your best bet is to include the appropriate meta tag: <META
HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">. Using the meta tag may help catch
more browsers than just the response header alone.
You might also try using a Response.Flush() right after you send the pragma
header. I've seen that help in some instances.
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
"Ryan Park" <bajy@.intizen.com> wrote in message
news:5016f0aa.0501030540.572182a1@.posting.google.com...
> Hi,
> I got a asp.net page that stores session variable.
> This page gets input parameter by QueryString and this variable stored
> into session variable.
> Asp.net page works in normal navigation scenario.
> Then I bookmarked this url to my favorites and call this url by
> clicking favorites link.
> When in this situation, at initial time Page_Load() of my asp.net gets
> called but after first time, page never get called by clicking
> favorites link.
> I guess maybe IE caches the link and read it when user clicks from
> favorite link.
> I've tried below codes only to fail to call Page_Load(). All of them
> failed.
> Response.Expires = 0;
> Response.Cache.SetNoStore();
> Response.AppendHeader("Pragma", "no-cache");
> Navigating my asp.net pages by favorites link is very possible user
> scenario.
> This is unavoidable.
> How can I always ensure IE to read URL from Web Server not from cache
> when user clicks favorites link?
> Any suggestion will be appreciated. TIA. :)
> Regards,
> Ryan
Mark Fitzpatrick wrote:
> Appending the header doesn't necessarily tell the browser not to
> cache the page.
That's correct -- the HTTP spec distinguishes between caches and histories.
For histories, Cache-Control and such do not apply.

> For that, your best bet is to include the appropriate
> meta tag: <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">. Using the
> meta tag may help catch more browsers than just the response header
> alone.
But only if the browser's HTTP implementation stinks. Out of curiosity: Can
you name any modern browser for which a META tag works, but a HTTP header
doesn't?
Cheers,
Joerg Jooss
www.joergjooss.de
news@.joergjooss.de

Serious cache problem - Page_Load get never get called !

Hi,

I got a asp.net page that stores session variable.

This page gets input parameter by QueryString and this variable stored
into session variable.

Asp.net page works in normal navigation scenario.

Then I bookmarked this url to my favorites and call this url by
clicking favorites link.

When in this situation, at initial time Page_Load() of my asp.net gets
called but after first time, page never get called by clicking
favorites link.

I guess maybe IE caches the link and read it when user clicks from
favorite link.

I've tried below codes only to fail to call Page_Load(). All of them
failed.

Response.Expires = 0;
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");

Navigating my asp.net pages by favorites link is very possible user
scenario.

This is unavoidable.

How can I always ensure IE to read URL from Web Server not from cache
when user clicks favorites link?

Any suggestion will be appreciated. TIA. :)

Regards,
RyanAppending the header doesn't necessarily tell the browser not to cache the
page. For that, your best bet is to include the appropriate meta tag: <META
HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">. Using the meta tag may help catch
more browsers than just the response header alone.

You might also try using a Response.Flush() right after you send the pragma
header. I've seen that help in some instances.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Ryan Park" <bajy@.intizen.com> wrote in message
news:5016f0aa.0501030540.572182a1@.posting.google.c om...
> Hi,
> I got a asp.net page that stores session variable.
> This page gets input parameter by QueryString and this variable stored
> into session variable.
> Asp.net page works in normal navigation scenario.
> Then I bookmarked this url to my favorites and call this url by
> clicking favorites link.
> When in this situation, at initial time Page_Load() of my asp.net gets
> called but after first time, page never get called by clicking
> favorites link.
> I guess maybe IE caches the link and read it when user clicks from
> favorite link.
> I've tried below codes only to fail to call Page_Load(). All of them
> failed.
> Response.Expires = 0;
> Response.Cache.SetNoStore();
> Response.AppendHeader("Pragma", "no-cache");
> Navigating my asp.net pages by favorites link is very possible user
> scenario.
> This is unavoidable.
> How can I always ensure IE to read URL from Web Server not from cache
> when user clicks favorites link?
> Any suggestion will be appreciated. TIA. :)
> Regards,
> Ryan
Mark Fitzpatrick wrote:
> Appending the header doesn't necessarily tell the browser not to
> cache the page.

That's correct -- the HTTP spec distinguishes between caches and histories.
For histories, Cache-Control and such do not apply.

> For that, your best bet is to include the appropriate
> meta tag: <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">. Using the
> meta tag may help catch more browsers than just the response header
> alone.

But only if the browser's HTTP implementation stinks. Out of curiosity: Can
you name any modern browser for which a META tag works, but a HTTP header
doesn't?

Cheers,

--
Joerg Jooss
www.joergjooss.de
news@.joergjooss.de

Serious Error Log

Hi everyone, i have just installed Microsoft V Studio.Net 2003 a few days ago.

There are occasions when im running my application, a kind of Blue screen will appear and shuts down my pc IMMEDIATELY. It all happen so fast, i couldn't see what was written on the blue screen.

After my pc reboot, a pop up window appears saying, "The system has recovered from a serious error."

After more clicking, they revealed that

"The following files will be included in this error report:

C:\WINDOWS\Minidump\Mini043004-01.dmp
C:\DOCUME~1\mtp\LOCALS~1\Temp\WER1.tmp.dir00\sysdata.xml
"

can anyone out there pls give me advice on how to tackle this problem?

any feedback will be greatly appreciated.

im on Win Xp.

ThanksAre you getting this error after you have installed Visual Studio .net
Please check that all service packs are installed on you system

Which OS you are using?

If you are using win 2003 get the latest patches
Yes, im getting this error after installing Visual Studio .net

I hope you can guide me here, what would you consider ALL service packs?

im running Windows XP Pro Operating System.

So is it a Windows XP problem or a Visual Studio .Net problem?

Do you have the links to download the patches?

It occasionally shuts down my pc while im trying to develop my web application.

Thanks for ur swift reply. Hopefully you can help me out here.
You can open the C:\WINDOWS\Minidump\Mini043004-01.dmp file in Notepad. What does it say?
okies, but i have already deleted the whole bunch of them.

Will try to open and see the contents when i hit this problem again.

Its worrying me cos it will always reboot my comp and im afraid it will damage my pc.

Thanks for the feedback, will keep you updated if i managed to view the contents of the minidump files.

Appreciate your reply.
ok hit the error again, opened up the mini dumo file.

Filled with incoherent symbols, alphanumeric mambo jumbo...

only managed to see a few lines of code which is readable

here it goes :

<s:Body>
<u:GetExternalIPAddress xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
</u:GetExternalIPAddress>
</s:Body
seriously i dun think all this will make any sense to you guys...

any help out there for me pls?

thanks.

Serious Exception

Hi,

I have a web application build in version .Net 1.1 & its successfully deployed to the server & running also.

But through my exception management library; I get following exception regularly in my inbox:

APPLICATION ERROR:

Error Details:System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (_ctl0:txtQuantity="...s too:
Time of Error:10/19/2006 8:13:47 PM

Please suggest me so that I can resolve this exception. If am not wrong this occurs 'coz of ViewState Curroption. But I dont have any idea to resolve it.

Thank you

i assumetxtQuantity is a textbox.

you can get away with that error by setting validateRequest attribute of the Page directive to false:

<%@. Page validateRequest="false" %>

check this for more details..

http://www.asp.net/faq/RequestValidation.aspx


HI,

Thanks for your grt reply.

I have already added Compare validator which accepts values greaterthanequal 1 even though I am getting this error. I am not getting know what will be the possible reason for this error.

Thank you


ASP.NET has a built-in function that checks whatever is input into a form for possible injection attacks (HTML, SQL, JavaScript, etc.) If anything looks funny, it will throw this exception.

While@. Page validateRequest="false" will work, you lose the built-in protection on the whole page. Not a good security practice.

It would be better in this case is to use Validation controls to prevent the page from even posting unless valid data is entered. For example, set it up so that txtQuantity only allows digits.


What value did you input in the TextBox when you get this error?

Thanks


Hello,

The textbox has one default value as 1. And this error comes when any user using the site. I dont know about what value does he enter.............

Thanks

Serious help needed with beta 2.0 SiteMapProvider..

All,

OK, so I'm working on a template for our new ASP.NET applications. Part of
this, includes using the new menu and breadcrumbs control in ASP.NET 2.0
(I'm using beta 2).

I put the hierarchy of the applications and navigation in a database, and am
able to pull that into the app by inheriting StaticSiteMapProvider. So
that's set and works great.

So then I realize that it builds the sitemap at the application level, not
at the user level. So I've been looking into how to restrict the menu
items - based on security I will get from the database.

In my inherited class, I override IsAccessibleToUser - and that seems to
work for the breadcrumbs (because it doesn't show anything if I go to an
"invalid" page) - but it doesn't do anything to the menu (or the treeview
either, for that matter). I basically check a couple hard-coded "roles" to
the "roles" that are associated with the current node.

From what I've been piecing together, it looks like the menu will only trim
away the unwanted menu items if the provider has the
securityTrimmingEnabled="true" - but when I try to add that to the
<providers> section in web.config - I get a red-squiggly and a compiler
warning that it's invalid (where it used to be valid in old versions).

BOTTOM LINE:
I need to prune the menu hierarchy based on user permissions. One user may
only see literally one item and another user may see a few dozen - or at
least that's what I need to replicate.

How can I have the menu control (or the treeview) prune away the things that
the current user isn't supposed to see??Have you tried to using the roles attribute in the site map file?

<siteMap>
<siteMapNode title="Home" description="" url="default.aspx">
<siteMapNode title="Announcements" url="Announcements.aspx"
description="Information for all employees" roles="*" />
<siteMapNode title="Salaries" url="Salaries.aspx"
description="Salary data" roles="Managers,CEOs" />
<siteMapNode>
</siteMap
I hope this helps

RedEye

"RCS" <rseder@.gmail.com> wrote in message
news:FQxBe.2901$Ih7.1828@.newssvr33.news.prodigy.co m...
> All,
> OK, so I'm working on a template for our new ASP.NET applications. Part of
> this, includes using the new menu and breadcrumbs control in ASP.NET 2.0
> (I'm using beta 2).
> I put the hierarchy of the applications and navigation in a database, and
> am able to pull that into the app by inheriting StaticSiteMapProvider. So
> that's set and works great.
> So then I realize that it builds the sitemap at the application level, not
> at the user level. So I've been looking into how to restrict the menu
> items - based on security I will get from the database.
> In my inherited class, I override IsAccessibleToUser - and that seems to
> work for the breadcrumbs (because it doesn't show anything if I go to an
> "invalid" page) - but it doesn't do anything to the menu (or the treeview
> either, for that matter). I basically check a couple hard-coded "roles" to
> the "roles" that are associated with the current node.
> From what I've been piecing together, it looks like the menu will only
> trim away the unwanted menu items if the provider has the
> securityTrimmingEnabled="true" - but when I try to add that to the
> <providers> section in web.config - I get a red-squiggly and a compiler
> warning that it's invalid (where it used to be valid in old versions).
> BOTTOM LINE:
> I need to prune the menu hierarchy based on user permissions. One user may
> only see literally one item and another user may see a few dozen - or at
> least that's what I need to replicate.
> How can I have the menu control (or the treeview) prune away the things
> that the current user isn't supposed to see??
Well, I'm creating the sitemap on the fly - but yes, this is exactly what
I'm doing.

The problem comes in with telling this sitemap (and the menu or the
treeview) that the currently logged in user does not have access to that
"Salaries" node in your example below.

And the academic solution from Microsoft is to put the users in your
web.config and use an <authorization> section to allow/deny people. But I
have a few thousand dynamic users - so I need to programatically validate
whether a user (and I know their roles) is supposed to see a particular node
item (which has a role associated).

*How* do I accomplish this?

"RedEye" <redeye_51@.hotmail.com> wrote in message
news:%23nLpLsKiFHA.2180@.TK2MSFTNGP15.phx.gbl...
> Have you tried to using the roles attribute in the site map file?
> <siteMap>
> <siteMapNode title="Home" description="" url="default.aspx">
> <siteMapNode title="Announcements" url="Announcements.aspx"
> description="Information for all employees" roles="*" />
> <siteMapNode title="Salaries" url="Salaries.aspx"
> description="Salary data" roles="Managers,CEOs" />
> <siteMapNode>
> </siteMap>
> I hope this helps
>
> RedEye
> "RCS" <rseder@.gmail.com> wrote in message
> news:FQxBe.2901$Ih7.1828@.newssvr33.news.prodigy.co m...
>> All,
>>
>> OK, so I'm working on a template for our new ASP.NET applications. Part
>> of this, includes using the new menu and breadcrumbs control in ASP.NET
>> 2.0 (I'm using beta 2).
>>
>> I put the hierarchy of the applications and navigation in a database, and
>> am able to pull that into the app by inheriting StaticSiteMapProvider. So
>> that's set and works great.
>>
>> So then I realize that it builds the sitemap at the application level,
>> not at the user level. So I've been looking into how to restrict the menu
>> items - based on security I will get from the database.
>>
>> In my inherited class, I override IsAccessibleToUser - and that seems to
>> work for the breadcrumbs (because it doesn't show anything if I go to an
>> "invalid" page) - but it doesn't do anything to the menu (or the treeview
>> either, for that matter). I basically check a couple hard-coded "roles"
>> to the "roles" that are associated with the current node.
>>
>> From what I've been piecing together, it looks like the menu will only
>> trim away the unwanted menu items if the provider has the
>> securityTrimmingEnabled="true" - but when I try to add that to the
>> <providers> section in web.config - I get a red-squiggly and a compiler
>> warning that it's invalid (where it used to be valid in old versions).
>>
>> BOTTOM LINE:
>> I need to prune the menu hierarchy based on user permissions. One user
>> may only see literally one item and another user may see a few dozen - or
>> at least that's what I need to replicate.
>>
>> How can I have the menu control (or the treeview) prune away the things
>> that the current user isn't supposed to see??
>>
>>
>>
Hi RCS:

It's true, you must use securityTrimmingEnabled="true". This works
well.

Ignore the red squiggly line. Unfortunately, the validation in VS 2005
can only take into consideration the settings that are common to all
site map providers. The securityTrimmingEnabled attribute is a setting
specific to the Xml site map provider that ships with asp.net 2.0. It
works, even though the IDE doesn't know about it, the provider does.

It's jus a case of the validation being a little overzealous.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 14 Jul 2005 18:06:29 GMT, "RCS" <rseder@.gmail.com> wrote:

>All,
>OK, so I'm working on a template for our new ASP.NET applications. Part of
>this, includes using the new menu and breadcrumbs control in ASP.NET 2.0
>(I'm using beta 2).
>I put the hierarchy of the applications and navigation in a database, and am
>able to pull that into the app by inheriting StaticSiteMapProvider. So
>that's set and works great.
>So then I realize that it builds the sitemap at the application level, not
>at the user level. So I've been looking into how to restrict the menu
>items - based on security I will get from the database.
>In my inherited class, I override IsAccessibleToUser - and that seems to
>work for the breadcrumbs (because it doesn't show anything if I go to an
>"invalid" page) - but it doesn't do anything to the menu (or the treeview
>either, for that matter). I basically check a couple hard-coded "roles" to
>the "roles" that are associated with the current node.
>From what I've been piecing together, it looks like the menu will only trim
>away the unwanted menu items if the provider has the
>securityTrimmingEnabled="true" - but when I try to add that to the
><providers> section in web.config - I get a red-squiggly and a compiler
>warning that it's invalid (where it used to be valid in old versions).
>BOTTOM LINE:
>I need to prune the menu hierarchy based on user permissions. One user may
>only see literally one item and another user may see a few dozen - or at
>least that's what I need to replicate.
>How can I have the menu control (or the treeview) prune away the things that
>the current user isn't supposed to see??
Scott - thanks..

Even if I do do this, A) if I do this in my page_load:

Response.Write(this.SiteMapDataSource1.Provider.Se curityTrimmingEnabled.ToString());

(Assuming that SiteMapDataSource1 points to my custom SiteMapProvider) - it
returns false. Then, in my class, I do this, to overwrite the default
implementation:

public new bool SecurityTrimmingEnabled = true;

Still - same result. It's beginning to look like I need to inherit from
higher up the tree - like SiteMapProvider (instead of
StaticSiteMapProvider) - or XmlSiteMapProvider or ProviderBase

But even if I did - and managed to get that to work, I'm not sure it will
solve my problem. Because at this point, I'm almost convinced that MY
sitemaprovider truly doesn't support SecurityTrimmingEnabled - and I don't
know where to begin, to make it support it.

Lastly - I could've solved all of this last week, if I could just build a
sitemap on a per-user basis (instead of per-application). I could handle all
the security in the database and just return the valid menu items for this
user.

Any ideas on how to make a sitemapprovider (and more specifically - a
SiteMapDataSource) - able to be used on a per-user basis?? Thanks again!

"Scott Allen" <scott@.nospam.odetocode.com> wrote in message
news:qiqfd1hdcmi580q1miap2i2n1khk1bi98s@.4ax.com...
> Hi RCS:
> It's true, you must use securityTrimmingEnabled="true". This works
> well.
> Ignore the red squiggly line. Unfortunately, the validation in VS 2005
> can only take into consideration the settings that are common to all
> site map providers. The securityTrimmingEnabled attribute is a setting
> specific to the Xml site map provider that ships with asp.net 2.0. It
> works, even though the IDE doesn't know about it, the provider does.
> It's jus a case of the validation being a little overzealous.
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
>
> On Thu, 14 Jul 2005 18:06:29 GMT, "RCS" <rseder@.gmail.com> wrote:
>>All,
>>
>>OK, so I'm working on a template for our new ASP.NET applications. Part of
>>this, includes using the new menu and breadcrumbs control in ASP.NET 2.0
>>(I'm using beta 2).
>>
>>I put the hierarchy of the applications and navigation in a database, and
>>am
>>able to pull that into the app by inheriting StaticSiteMapProvider. So
>>that's set and works great.
>>
>>So then I realize that it builds the sitemap at the application level, not
>>at the user level. So I've been looking into how to restrict the menu
>>items - based on security I will get from the database.
>>
>>In my inherited class, I override IsAccessibleToUser - and that seems to
>>work for the breadcrumbs (because it doesn't show anything if I go to an
>>"invalid" page) - but it doesn't do anything to the menu (or the treeview
>>either, for that matter). I basically check a couple hard-coded "roles" to
>>the "roles" that are associated with the current node.
>>
>>From what I've been piecing together, it looks like the menu will only
>>trim
>>away the unwanted menu items if the provider has the
>>securityTrimmingEnabled="true" - but when I try to add that to the
>><providers> section in web.config - I get a red-squiggly and a compiler
>>warning that it's invalid (where it used to be valid in old versions).
>>
>>BOTTOM LINE:
>>I need to prune the menu hierarchy based on user permissions. One user may
>>only see literally one item and another user may see a few dozen - or at
>>least that's what I need to replicate.
>>
>>How can I have the menu control (or the treeview) prune away the things
>>that
>>the current user isn't supposed to see??
>>
>
Hi Rcs:

You can always plug your own custom site map provider in, although
I've been using security trimming so that should work. It will build
the menu control such that the user only sees what they are allowed to
navigate to.

In the providers section, did you have a <remove> element in to make
sure it's not using the default configuration?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 15 Jul 2005 17:27:50 GMT, "RCS" <rseder@.gmail.com> wrote:

>Scott - thanks..
>Even if I do do this, A) if I do this in my page_load:
> Response.Write(this.SiteMapDataSource1.Provider.Se curityTrimmingEnabled.ToString());
>(Assuming that SiteMapDataSource1 points to my custom SiteMapProvider) - it
>returns false. Then, in my class, I do this, to overwrite the default
>implementation:
> public new bool SecurityTrimmingEnabled = true;
>Still - same result. It's beginning to look like I need to inherit from
>higher up the tree - like SiteMapProvider (instead of
>StaticSiteMapProvider) - or XmlSiteMapProvider or ProviderBase
>But even if I did - and managed to get that to work, I'm not sure it will
>solve my problem. Because at this point, I'm almost convinced that MY
>sitemaprovider truly doesn't support SecurityTrimmingEnabled - and I don't
>know where to begin, to make it support it.
>
>Lastly - I could've solved all of this last week, if I could just build a
>sitemap on a per-user basis (instead of per-application). I could handle all
>the security in the database and just return the valid menu items for this
>user.
>Any ideas on how to make a sitemapprovider (and more specifically - a
>SiteMapDataSource) - able to be used on a per-user basis?? Thanks again!
>
>"Scott Allen" <scott@.nospam.odetocode.com> wrote in message
>news:qiqfd1hdcmi580q1miap2i2n1khk1bi98s@.4ax.com...
>> Hi RCS:
>>
>> It's true, you must use securityTrimmingEnabled="true". This works
>> well.
>>
>> Ignore the red squiggly line. Unfortunately, the validation in VS 2005
>> can only take into consideration the settings that are common to all
>> site map providers. The securityTrimmingEnabled attribute is a setting
>> specific to the Xml site map provider that ships with asp.net 2.0. It
>> works, even though the IDE doesn't know about it, the provider does.
>>
>> It's jus a case of the validation being a little overzealous.
>>
>> --
>> Scott
>> http://www.OdeToCode.com/blogs/scott/
>>
>>
>> On Thu, 14 Jul 2005 18:06:29 GMT, "RCS" <rseder@.gmail.com> wrote:
>>
>>>All,
>>>
>>>OK, so I'm working on a template for our new ASP.NET applications. Part of
>>>this, includes using the new menu and breadcrumbs control in ASP.NET 2.0
>>>(I'm using beta 2).
>>>
>>>I put the hierarchy of the applications and navigation in a database, and
>>>am
>>>able to pull that into the app by inheriting StaticSiteMapProvider. So
>>>that's set and works great.
>>>
>>>So then I realize that it builds the sitemap at the application level, not
>>>at the user level. So I've been looking into how to restrict the menu
>>>items - based on security I will get from the database.
>>>
>>>In my inherited class, I override IsAccessibleToUser - and that seems to
>>>work for the breadcrumbs (because it doesn't show anything if I go to an
>>>"invalid" page) - but it doesn't do anything to the menu (or the treeview
>>>either, for that matter). I basically check a couple hard-coded "roles" to
>>>the "roles" that are associated with the current node.
>>>
>>>From what I've been piecing together, it looks like the menu will only
>>>trim
>>>away the unwanted menu items if the provider has the
>>>securityTrimmingEnabled="true" - but when I try to add that to the
>>><providers> section in web.config - I get a red-squiggly and a compiler
>>>warning that it's invalid (where it used to be valid in old versions).
>>>
>>>BOTTOM LINE:
>>>I need to prune the menu hierarchy based on user permissions. One user may
>>>only see literally one item and another user may see a few dozen - or at
>>>least that's what I need to replicate.
>>>
>>>How can I have the menu control (or the treeview) prune away the things
>>>that
>>>the current user isn't supposed to see??
>>>
>>>
>
Hiya,

I'm already doing that - I inherited from StaticSiteMapProvider - and the
menu is populated correctly with ALL possible menu options (from a SQL
databsae) - including menu options inappropriate for some users.

Assuming my inherited is named MySiteMapProvider - I have this in my
web.config:

<siteMap defaultProvider="MySiteMapProvider" enabled="true">
<providers>
<clear/>
<add name="MySiteMapProvider" securityTrimmingEnabled="true"
type="MySiteMapProvider"></add>
</providers>
</siteMap
And again - my provider works perfectly. The problem is, I need to prune
back menu items (or nodes within the provider) so that the current user sees
the appropriate menu items.

I think I've hit the end of the Internet - I've scoured every resource I
know and I'm pretty much at a standstill.

thanks again!

"Scott Allen" <scott@.nospam.odetocode.com> wrote in message
news:s4vfd1hrapgth9ta49mn4goj4fq4hbh5c4@.4ax.com...
> Hi Rcs:
> You can always plug your own custom site map provider in, although
> I've been using security trimming so that should work. It will build
> the menu control such that the user only sees what they are allowed to
> navigate to.
> In the providers section, did you have a <remove> element in to make
> sure it's not using the default configuration?
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
> On Fri, 15 Jul 2005 17:27:50 GMT, "RCS" <rseder@.gmail.com> wrote:
>>Scott - thanks..
>>
>>Even if I do do this, A) if I do this in my page_load:
>>
>>
>> Response.Write(this.SiteMapDataSource1.Provider.Se curityTrimmingEnabled.ToString());
>>
>>(Assuming that SiteMapDataSource1 points to my custom SiteMapProvider) -
>>it
>>returns false. Then, in my class, I do this, to overwrite the default
>>implementation:
>>
>> public new bool SecurityTrimmingEnabled = true;
>>
>>Still - same result. It's beginning to look like I need to inherit from
>>higher up the tree - like SiteMapProvider (instead of
>>StaticSiteMapProvider) - or XmlSiteMapProvider or ProviderBase
>>
>>But even if I did - and managed to get that to work, I'm not sure it will
>>solve my problem. Because at this point, I'm almost convinced that MY
>>sitemaprovider truly doesn't support SecurityTrimmingEnabled - and I don't
>>know where to begin, to make it support it.
>>
>>
>>Lastly - I could've solved all of this last week, if I could just build a
>>sitemap on a per-user basis (instead of per-application). I could handle
>>all
>>the security in the database and just return the valid menu items for this
>>user.
>>
>>Any ideas on how to make a sitemapprovider (and more specifically - a
>>SiteMapDataSource) - able to be used on a per-user basis?? Thanks again!
>>
>>
>>"Scott Allen" <scott@.nospam.odetocode.com> wrote in message
>>news:qiqfd1hdcmi580q1miap2i2n1khk1bi98s@.4ax.com...
>>> Hi RCS:
>>>
>>> It's true, you must use securityTrimmingEnabled="true". This works
>>> well.
>>>
>>> Ignore the red squiggly line. Unfortunately, the validation in VS 2005
>>> can only take into consideration the settings that are common to all
>>> site map providers. The securityTrimmingEnabled attribute is a setting
>>> specific to the Xml site map provider that ships with asp.net 2.0. It
>>> works, even though the IDE doesn't know about it, the provider does.
>>>
>>> It's jus a case of the validation being a little overzealous.
>>>
>>> --
>>> Scott
>>> http://www.OdeToCode.com/blogs/scott/
>>>
>>>
>>> On Thu, 14 Jul 2005 18:06:29 GMT, "RCS" <rseder@.gmail.com> wrote:
>>>
>>>>All,
>>>>
>>>>OK, so I'm working on a template for our new ASP.NET applications. Part
>>>>of
>>>>this, includes using the new menu and breadcrumbs control in ASP.NET 2.0
>>>>(I'm using beta 2).
>>>>
>>>>I put the hierarchy of the applications and navigation in a database,
>>>>and
>>>>am
>>>>able to pull that into the app by inheriting StaticSiteMapProvider. So
>>>>that's set and works great.
>>>>
>>>>So then I realize that it builds the sitemap at the application level,
>>>>not
>>>>at the user level. So I've been looking into how to restrict the menu
>>>>items - based on security I will get from the database.
>>>>
>>>>In my inherited class, I override IsAccessibleToUser - and that seems to
>>>>work for the breadcrumbs (because it doesn't show anything if I go to an
>>>>"invalid" page) - but it doesn't do anything to the menu (or the
>>>>treeview
>>>>either, for that matter). I basically check a couple hard-coded "roles"
>>>>to
>>>>the "roles" that are associated with the current node.
>>>>
>>>>From what I've been piecing together, it looks like the menu will only
>>>>trim
>>>>away the unwanted menu items if the provider has the
>>>>securityTrimmingEnabled="true" - but when I try to add that to the
>>>><providers> section in web.config - I get a red-squiggly and a compiler
>>>>warning that it's invalid (where it used to be valid in old versions).
>>>>
>>>>BOTTOM LINE:
>>>>I need to prune the menu hierarchy based on user permissions. One user
>>>>may
>>>>only see literally one item and another user may see a few dozen - or at
>>>>least that's what I need to replicate.
>>>>
>>>>How can I have the menu control (or the treeview) prune away the things
>>>>that
>>>>the current user isn't supposed to see??
>>>>
>>>>
>>>
>
I know there is not a tremendous amount published yet in this area.
Best of luck.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 15 Jul 2005 18:27:28 GMT, "RCS" <rseder@.gmail.com> wrote:

>Hiya,
>I'm already doing that - I inherited from StaticSiteMapProvider - and the
>menu is populated correctly with ALL possible menu options (from a SQL
>databsae) - including menu options inappropriate for some users.
>Assuming my inherited is named MySiteMapProvider - I have this in my
>web.config:
><siteMap defaultProvider="MySiteMapProvider" enabled="true">
> <providers>
> <clear/>
> <add name="MySiteMapProvider" securityTrimmingEnabled="true"
>type="MySiteMapProvider"></add>
> </providers>
></siteMap>
>And again - my provider works perfectly. The problem is, I need to prune
>back menu items (or nodes within the provider) so that the current user sees
>the appropriate menu items.
>I think I've hit the end of the Internet - I've scoured every resource I
>know and I'm pretty much at a standstill.
>thanks again!
Not much except for here: http://msdn2.microsoft.com/library/e468hxky.aspx
Some good forum posts at
http://forums.asp.net/search/Search...ytrimming&f=&u= too.

--JF

"Scott Allen" wrote:

> I know there is not a tremendous amount published yet in this area.
> Best of luck.
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
> On Fri, 15 Jul 2005 18:27:28 GMT, "RCS" <rseder@.gmail.com> wrote:
> >Hiya,
> >I'm already doing that - I inherited from StaticSiteMapProvider - and the
> >menu is populated correctly with ALL possible menu options (from a SQL
> >databsae) - including menu options inappropriate for some users.
> >Assuming my inherited is named MySiteMapProvider - I have this in my
> >web.config:
> ><siteMap defaultProvider="MySiteMapProvider" enabled="true">
> > <providers>
> > <clear/>
> > <add name="MySiteMapProvider" securityTrimmingEnabled="true"
> >type="MySiteMapProvider"></add>
> > </providers>
> ></siteMap>
> >And again - my provider works perfectly. The problem is, I need to prune
> >back menu items (or nodes within the provider) so that the current user sees
> >the appropriate menu items.
> >I think I've hit the end of the Internet - I've scoured every resource I
> >know and I'm pretty much at a standstill.
> >thanks again!
>

Serious issue with HttpContext.Current.User.Identity.Name

I have a serious issue that seems to be intermittent with
User.Identity.Name.

In an environment where about 100+ users are logging on to a site with
forms authentication, calling HttpContext.Current.User.Identity.Name
returns the correctly logged on user.

However, 10% of the time (I'm guessing under stress conditions or
simulataneous requests), the wrong user info is being returned.

The logic of this app:

1) User enters username/pass
2) Info is looked up via SQL DB call
3) If match, user is authenticated via
FormsAuthentication.RedirectFromLoginPage(username , True)
4) On all the pages the user visits, his/her info is shown via a call
to HttpContext.Current.User.Identity.Name

This works almost all the time. Any ideas why it might be failing from
time to time?usually a coding error where you store the user info in a vb module or c#
static during page processing.

-- bruce (sqlwork.com)

<kiran_s_rao@.hotmail.com> wrote in message
news:1102451962.249708.187910@.f14g2000cwb.googlegr oups.com...
| I have a serious issue that seems to be intermittent with
| User.Identity.Name.
|
| In an environment where about 100+ users are logging on to a site with
| forms authentication, calling HttpContext.Current.User.Identity.Name
| returns the correctly logged on user.
|
| However, 10% of the time (I'm guessing under stress conditions or
| simulataneous requests), the wrong user info is being returned.
|
| The logic of this app:
|
| 1) User enters username/pass
| 2) Info is looked up via SQL DB call
| 3) If match, user is authenticated via
| FormsAuthentication.RedirectFromLoginPage(username , True)
| 4) On all the pages the user visits, his/her info is shown via a call
| to HttpContext.Current.User.Identity.Name
|
| This works almost all the time. Any ideas why it might be failing from
| time to time?
|
Bruce,

Thanks for the reply.
Can you please give me more detail?

When you say "coding error where you store the user info", what is the
common error here?

We are not storing that info anywhere, but just calling
HttpContext.Current.User.Identity.Name whenever we need that info.
Sometimes it's correct, sometimes it's not.

Kiran
Bruce,

Thanks for the reply.
Can you please give me more detail?

When you say "coding error where you store the user info", what is the
common error here?

We are not storing that info anywhere, but just calling
HttpContext.Current.User.Identity.Name whenever we need that info.
Sometimes it's correct, sometimes it's not.

Kiran
Hi Kiran..
Are you using Forms Authentication and validating against SQL Server?
Are u sure u aren;t using Windows Auth since u are calling :-
HttpContext.Current.User.Identity.Name
Pls Elaborate more..
Patrick

"kiran_s_rao@.hotmail.com" wrote:

> I have a serious issue that seems to be intermittent with
> User.Identity.Name.
> In an environment where about 100+ users are logging on to a site with
> forms authentication, calling HttpContext.Current.User.Identity.Name
> returns the correctly logged on user.
> However, 10% of the time (I'm guessing under stress conditions or
> simulataneous requests), the wrong user info is being returned.
> The logic of this app:
> 1) User enters username/pass
> 2) Info is looked up via SQL DB call
> 3) If match, user is authenticated via
> FormsAuthentication.RedirectFromLoginPage(username , True)
> 4) On all the pages the user visits, his/her info is shown via a call
> to HttpContext.Current.User.Identity.Name
> This works almost all the time. Any ideas why it might be failing from
> time to time?
>
Patrick,

Thanks for the reply.
Ok here is what I'm doing:

1) User enters user and pass
2) Check for match with SQL DB
3) If match, call FormsAuthentication.RedirectFromLoginPage(username ,
True)

After all that, I was under the impression that the best way to check
for the currently logged in user is to call:
HttpContext.Current.User.Identity.Name

Is this not correct? How else do you check the name with Forms
Authentication?

Thanks,
Kiran
Hello kiran_s_rao@.hotmail.com,

You are correct. My guess is that somewhere you're storing/retrieving this
info from a static variable...

--
Matt Berther
http://www.mattberther.com

> Patrick,
> Thanks for the reply.
> Ok here is what I'm doing:
> 1) User enters user and pass
> 2) Check for match with SQL DB
> 3) If match, call FormsAuthentication.RedirectFromLoginPage(username ,
> True)
> After all that, I was under the impression that the best way to check
> for the currently logged in user is to call:
> HttpContext.Current.User.Identity.Name
> Is this not correct? How else do you check the name with Forms
> Authentication?
> Thanks,
> Kiran
HI Kiran
As Matt stated you're storing/retrieving somewhere..!
With your Forms Auth validating against SQL server are u implementing
ROLES(Authorisation)..b-cos if you do then u must be storing USERS for
sure..
B-cos by calling "HttpContext.Current.User.Identity.Name"
ur just calling the logged on user..
Hope it helps..
Patrick
**Let me read from you**

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Thanks for all the replies.

However, we are *not* storing this information anywhere at all.
We are not doing roles based auth.

Whenever we need to figure out who the current user is, we call
HttpContext.Current.User.Identity.Name. This is not stored in a
variable anywhere.

Am I understanding the above call correctly? If user "a" logs in and
then user "b" logs in, does calling identity.name for user "a"'s
session show user "b"'s info? Because that is what is happening with
10% of the requests.
Kiran_S_Rao,
This seems wierd!
When u talk about INFO do you mean the USerName?
Are 10% of this users in the same Domain?
As u are using Forms Auth do you have Anonymous Acces turned OFF or ON?
Patrick

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Patrick,

Yes, the info that I was referring to was the Username.
When I say 10% of the calls fail, what I mean is that sometimes, a
given user's session will return someone else's Username.
This is not predicatable and does not happen to a certain set of
people. All the users have this happen sooner or later. There is no
domain distinction since the usernames are held in the DB, and have
nothing to do with the domain of the server.

In IIS, I have anonymous access turned ON so unregistered users can
access the rest of the site.

Serious issue with HttpContext.Current.User.Identity.Name

I have a serious issue that seems to be intermittent with
User.Identity.Name.
In an environment where about 100+ users are logging on to a site with
forms authentication, calling HttpContext.Current.User.Identity.Name
returns the correctly logged on user.
However, 10% of the time (I'm guessing under stress conditions or
simulataneous requests), the wrong user info is being returned.
The logic of this app:
1) User enters username/pass
2) Info is looked up via SQL DB call
3) If match, user is authenticated via
FormsAuthentication.RedirectFromLoginPage(username, True)
4) On all the pages the user visits, his/her info is shown via a call
to HttpContext.Current.User.Identity.Name
This works almost all the time. Any ideas why it might be failing from
time to time?usually a coding error where you store the user info in a vb module or c#
static during page processing.
-- bruce (sqlwork.com)
<kiran_s_rao@.hotmail.com> wrote in message
news:1102451962.249708.187910@.f14g2000cwb.googlegroups.com...
| I have a serious issue that seems to be intermittent with
| User.Identity.Name.
|
| In an environment where about 100+ users are logging on to a site with
| forms authentication, calling HttpContext.Current.User.Identity.Name
| returns the correctly logged on user.
|
| However, 10% of the time (I'm guessing under stress conditions or
| simulataneous requests), the wrong user info is being returned.
|
| The logic of this app:
|
| 1) User enters username/pass
| 2) Info is looked up via SQL DB call
| 3) If match, user is authenticated via
| FormsAuthentication.RedirectFromLoginPage(username, True)
| 4) On all the pages the user visits, his/her info is shown via a call
| to HttpContext.Current.User.Identity.Name
|
| This works almost all the time. Any ideas why it might be failing from
| time to time?
|
Bruce,
Thanks for the reply.
Can you please give me more detail?
When you say "coding error where you store the user info", what is the
common error here?
We are not storing that info anywhere, but just calling
HttpContext.Current.User.Identity.Name whenever we need that info.
Sometimes it's correct, sometimes it's not.
Kiran
Bruce,
Thanks for the reply.
Can you please give me more detail?
When you say "coding error where you store the user info", what is the
common error here?
We are not storing that info anywhere, but just calling
HttpContext.Current.User.Identity.Name whenever we need that info.
Sometimes it's correct, sometimes it's not.
Kiran
Hi Kiran..
Are you using Forms Authentication and validating against SQL Server?
Are u sure u aren;t using Windows Auth since u are calling :-
HttpContext.Current.User.Identity.Name
Pls Elaborate more..
Patrick
"kiran_s_rao@.hotmail.com" wrote:

> I have a serious issue that seems to be intermittent with
> User.Identity.Name.
> In an environment where about 100+ users are logging on to a site with
> forms authentication, calling HttpContext.Current.User.Identity.Name
> returns the correctly logged on user.
> However, 10% of the time (I'm guessing under stress conditions or
> simulataneous requests), the wrong user info is being returned.
> The logic of this app:
> 1) User enters username/pass
> 2) Info is looked up via SQL DB call
> 3) If match, user is authenticated via
> FormsAuthentication.RedirectFromLoginPage(username, True)
> 4) On all the pages the user visits, his/her info is shown via a call
> to HttpContext.Current.User.Identity.Name
> This works almost all the time. Any ideas why it might be failing from
> time to time?
>
Patrick,
Thanks for the reply.
Ok here is what I'm doing:
1) User enters user and pass
2) Check for match with SQL DB
3) If match, call FormsAuthentication.RedirectFromLoginPage(username,
True)
After all that, I was under the impression that the best way to check
for the currently logged in user is to call:
HttpContext.Current.User.Identity.Name
Is this not correct? How else do you check the name with Forms
Authentication?
Thanks,
Kiran
Hello kiran_s_rao@.hotmail.com,
You are correct. My guess is that somewhere you're storing/retrieving this
info from a static variable...
Matt Berther
http://www.mattberther.com

> Patrick,
> Thanks for the reply.
> Ok here is what I'm doing:
> 1) User enters user and pass
> 2) Check for match with SQL DB
> 3) If match, call FormsAuthentication.RedirectFromLoginPage(username,
> True)
> After all that, I was under the impression that the best way to check
> for the currently logged in user is to call:
> HttpContext.Current.User.Identity.Name
> Is this not correct? How else do you check the name with Forms
> Authentication?
> Thanks,
> Kiran
HI Kiran
As Matt stated you're storing/retrieving somewhere..!
With your Forms Auth validating against SQL server are u implementing
ROLES(Authorisation)..b-cos if you do then u must be storing USERS for
sure..
B-cos by calling "HttpContext.Current.User.Identity.Name"
ur just calling the logged on user..
Hope it helps..
Patrick
**Let me read from you**
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
Thanks for all the replies.
However, we are *not* storing this information anywhere at all.
We are not doing roles based auth.
Whenever we need to figure out who the current user is, we call
HttpContext.Current.User.Identity.Name. This is not stored in a
variable anywhere.
Am I understanding the above call correctly? If user "a" logs in and
then user "b" logs in, does calling identity.name for user "a"'s
session show user "b"'s info? Because that is what is happening with
10% of the requests.
Kiran_S_Rao,
This seems wierd!
When u talk about INFO do you mean the USerName?
Are 10% of this users in the same Domain?
As u are using Forms Auth do you have Anonymous Acces turned OFF or ON?
Patrick
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!

Serious limitation of ObjectDataSource + DataObjectTypeName + DataSet as BusinessEntity

Hi fellas,

has anyone managed to get ObjectDataSource to work Datasets where the
Dataset is used as BusinessEntity class?

What I mean is the following architecture:

1.WebPage with ObjectDataSource
2. CustomBusinessObject which
* does validation,
* uses a Strongly Typed DataTable as a collection of BusinessEntity
items
* forwards data access to DataAdapters as a data layer
3. DataLayer based on DataAdapters

Ideally I would like to use the DataObjectTypeName property of the
ObjectDataSource
so that the methods of the CustomBusinessObject are with a single
parameter e.g.
Insert (Customer c);
The problem stems from the fact that the ObjectDataSouce requires the
BusinessEntity class (in this case this would be strongly typed data
row) should have a default constructor. Unfortunately, I could not
figure way of implementing a strongly typed data row with default
constructor.

Is there any way around this situation?

The only solution I could come up with so far is to not set the
DataObjectTypeName and handle the ObjectDataSource's Inserting,
Updating and Deleting events ... but this still requires a fair amount
of trivial code.

It would have been great if there was a way to plug into the creation
of BusinessEntity instances instead of relying on default constructors
...

Cheers,

MillenThe ObjectDataSource isn't designed with extensibility in mind so you
have to adapt to it.

If you need more customization, you can use my ExtendedObjectDataSource
that has more features and comes with full source so you can modify
what you want:

http://www.manuelabadia.com/products/EODS_features.aspx

Right now to create the object it uses
Activator.CreateInstance(dataObjectType) but you can change it to
whatever you need.

Manu

Serious issues with webcontrols...

Hi,

First of all, sorry for cross-posting, but some groups look more active than
others, and I sure need to find an answer to this.

I recently rebuilt my website using ASP.NET and I did my forum system using
a datagrid and template columns. I was asked by many users to remove the
LinkButton in order to be able to "open in a new window", so instead I used
the hyperlink control to allow users to access the message page from the
topic list page.

But for some reason, and don't ask me why, some users don't see the
hyperlinks at ALL!

One user mailed me, and the HTML generated by IIS for him, the code:

<a id="dgList__ctl8_hlThreadName"

Is replaced by:

<!--d="dgList__ctl8_hlThreadName"

You see? HTML comment! I have no idea why it does that!!! And that is under
Windows 98 using IE (don't know which version, but he said "old")

Another use, I'm using HyperLink controls with an image, and they simply
don't see the image at all.. is there a problem with the HyperLink control?

This is not counting the multiple viewstate problem I'm having.. I love
programming in .NET, but there are serious issues when it comes to
multi-platform.. should I be surprised that the WIDTH/HEIGHT tags of an
imagebutton control are lost when a user uses Netscape?

If some people want to see them live to see what's wrong, then...

http://www.neworderonline.com/Threa...aspx?ForumID=11

This is the technical support forum, most issues are posted there.. and I
receive all errors by email, so I can tell there are not many in the forum
system, I do however receive corrupted viewstate errors from time to time...Try adjusting the target browser. You've got the browser schema set to IE 5
or above. Try setting it for a more neutral HTML 3.2 compliant browser.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Nicolas LeBlanc" <nicolas_leblanc@.nomoreSPAM.hotmail.com> wrote in message
news:eUtHtJ%23mDHA.2456@.TK2MSFTNGP09.phx.gbl...
> Hi,
> First of all, sorry for cross-posting, but some groups look more active
than
> others, and I sure need to find an answer to this.
> I recently rebuilt my website using ASP.NET and I did my forum system
using
> a datagrid and template columns. I was asked by many users to remove the
> LinkButton in order to be able to "open in a new window", so instead I
used
> the hyperlink control to allow users to access the message page from the
> topic list page.
> But for some reason, and don't ask me why, some users don't see the
> hyperlinks at ALL!
> One user mailed me, and the HTML generated by IIS for him, the code:
> <a id="dgList__ctl8_hlThreadName"
> Is replaced by:
> <!--d="dgList__ctl8_hlThreadName"
> You see? HTML comment! I have no idea why it does that!!! And that is
under
> Windows 98 using IE (don't know which version, but he said "old")
> Another use, I'm using HyperLink controls with an image, and they simply
> don't see the image at all.. is there a problem with the HyperLink
control?
> This is not counting the multiple viewstate problem I'm having.. I love
> programming in .NET, but there are serious issues when it comes to
> multi-platform.. should I be surprised that the WIDTH/HEIGHT tags of an
> imagebutton control are lost when a user uses Netscape?
> If some people want to see them live to see what's wrong, then...
> http://www.neworderonline.com/Threa...aspx?ForumID=11
> This is the technical support forum, most issues are posted there.. and I
> receive all errors by email, so I can tell there are not many in the forum
> system, I do however receive corrupted viewstate errors from time to
time...

Serious issue: parts of my page render as not logged in, parts as logged in. Help!

I'm having a very difficult time with some of our new pages. We've
moved to a web farm, and it seems in spurts it will come where parts
of my page think the user is logged in, and parts think the user is
not logged in. It seems to happen to an entire control. (None of the
controls have OutputCache set)

For example, our login control on top will appear showing the user is
logged inw hen they have been redirected to RegNewUser, but RegNewUser
will display instead of redirecting as if the user were actually
logged in.

The MachineKey option in the web.config is set to a generated SHA1, so
the viewstate moves between the web servers just fine.

This seems to come in spurts where it will happen to a lot of users at
once, then it will stop coming. This is a serious problem on a
production website, I just don't know where to turn or how to debug --
everything looks fine!

I am also getting Forms Authentication failed events in my log:

Event code: 4005
Event message: Forms authentication failed for the request. Reason:
The ticket supplied has expired.
Event time: 4/11/2007 12:42:27 PM
Event time (UTC): 4/11/2007 7:42:27 PM
Event ID: 0a0a593d17984b41aa13b93254491326
Event sequence: 1161
Event occurrence: 13
Event detail code: 50202

Application information:
Application domain: /LM/W3SVC/1/Root-2-128207889508981002
Trust level: Full
Application Virtual Path: /
Application Path: E:\htdocs\mysite-pri\
Machine name: WEB1

Process information:
Process ID: 400
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE

Request information:
Request URL: http://www.mysite.com:8080/default.aspx
Request path: /default.aspx
User host address: 10.10.1.1
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE

Name to authenticate:

Custom event details:Make sure the cookie path is the same on all machines. Make sure that the Web
Site number (e.g., /LM/W3SVC/1/Root-2-128207889508981002 - the "/1/" after
W3SVC) is the same.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"pcloches@.gmail.com" wrote:

Quote:

Originally Posted by

I'm having a very difficult time with some of our new pages. We've
moved to a web farm, and it seems in spurts it will come where parts
of my page think the user is logged in, and parts think the user is
not logged in. It seems to happen to an entire control. (None of the
controls have OutputCache set)
>
For example, our login control on top will appear showing the user is
logged inw hen they have been redirected to RegNewUser, but RegNewUser
will display instead of redirecting as if the user were actually
logged in.
>
The MachineKey option in the web.config is set to a generated SHA1, so
the viewstate moves between the web servers just fine.
>
This seems to come in spurts where it will happen to a lot of users at
once, then it will stop coming. This is a serious problem on a
production website, I just don't know where to turn or how to debug --
everything looks fine!
>
I am also getting Forms Authentication failed events in my log:
>
Event code: 4005
Event message: Forms authentication failed for the request. Reason:
The ticket supplied has expired.
Event time: 4/11/2007 12:42:27 PM
Event time (UTC): 4/11/2007 7:42:27 PM
Event ID: 0a0a593d17984b41aa13b93254491326
Event sequence: 1161
Event occurrence: 13
Event detail code: 50202
>
Application information:
Application domain: /LM/W3SVC/1/Root-2-128207889508981002
Trust level: Full
Application Virtual Path: /
Application Path: E:\htdocs\mysite-pri\
Machine name: WEB1
>
Process information:
Process ID: 400
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE
>
Request information:
Request URL: http://www.mysite.com:8080/default.aspx
Request path: /default.aspx
User host address: 10.10.1.1
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE
>
Name to authenticate:
>
Custom event details:
>
>

serious problem running asp.net and framework on domain controller

I have a web server which is also the domain controller. Windows2000.
The problem is that in my application I get the error once in a while:
Failed to create file C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary
ASP.NET Files\root\af32ae93\a2206a1a\pturxxyg.out.
or a similar file in the same directory.
If I give "Authenticated Users" Full Control (has to write), and restart
(!!) the IIS (thought this belonged to the past). The problem is solved.
However, this server "restores" its system NTFS security settings at
intervals. And at some stage, with the permissions gone, the same problem
will occur again.
- In the ASP.NET application I use user impersonization, but I don't know if
this is connected.
- The problem comes back all the time, obviously always at the wrong time.
- I don't know which user actually lacks the permission. I tried to find out
by trying, but this didn't help. The impersonated user is an administrator,
and the we are talking about active directory. If I would know which user
tried to make this call (I tried the user used to logon and the internet
user, to no avail), then this would help in some way.
Can anyone advise me on how to get past this problem once and for all? It
seems unrealistic that my application environment would be incompatible with
itself.
Help is very much appreciated!
Leo Muller,
Web developerI have the same thing going on here.
I have uninstalled the .NET Framework, and IIS, then re-installed IIS,
then the .NET Framework.
Anyone have any other ideas?
Regards,
Matt
"Leo Muller" <leo-m@.keshet-i.com> wrote in message news:<cimfl0$gds$1@.news2.netvision.net.i
l>...
> I have a web server which is also the domain controller. Windows2000.
> The problem is that in my application I get the error once in a while:
> Failed to create file C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary
> ASP.NET Files\root\af32ae93\a2206a1a\pturxxyg.out.
> or a similar file in the same directory.
> If I give "Authenticated Users" Full Control (has to write), and restart
> (!!) the IIS (thought this belonged to the past). The problem is solved.
> However, this server "restores" its system NTFS security settings at
> intervals. And at some stage, with the permissions gone, the same problem
> will occur again.
> - In the ASP.NET application I use user impersonization, but I don't know
if
> this is connected.
> - The problem comes back all the time, obviously always at the wrong time.
> - I don't know which user actually lacks the permission. I tried to find o
ut
> by trying, but this didn't help. The impersonated user is an administrator
,
> and the we are talking about active directory. If I would know which user
> tried to make this call (I tried the user used to logon and the internet
> user, to no avail), then this would help in some way.
> Can anyone advise me on how to get past this problem once and for all? It
> seems unrealistic that my application environment would be incompatible wi
th
> itself.
> Help is very much appreciated!
> Leo Muller,
> Web developer

Serious Probelm

Hi all,

I am using Web Matrix and C#. When I run code in .aspx file at home on my laptop, it works perfect with no errors. However when I try and run it on a computer in my college lab I get the following errors....

Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request failed.

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@dotnet.itags.org. Page Language="C#" Debug="true" %
or:

2) Add the following section to the configuration file of your application:

<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration
Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:

[SecurityException: Request failed.]
DatabaseConnect.DBConnect.Details() +0
DatabaseConnect.DBConnect.Main() +10
_ASP.common_ascx.Page_Load(Object sender, EventArgs e) +44
System.Web.UI.Control.OnLoad(EventArgs e) +55
System.Web.UI.Control.LoadRecursive() +21
System.Web.UI.Control.LoadRecursive() +84
System.Web.UI.Page.ProcessRequestMain() +2095
System.Web.UI.Page.ProcessRequest() +115
System.Web.UI.Page.ProcessRequest(HttpContext context) +18
System.Web.CallHandlerExecutionStep.Execute() +179
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +87

From my understanding of the error, it seems a security/permissions problem but not sure what I should ask or say to the administrator about it or what fix I should suggest. Any suggestions please? Also as the files will be hosted on a web server soon, is it possible I may get the same problems there?

Help is really needed on this and would be extremely appreciated.Set debug to true in the page directive. It will tell you more information then now. After that you may have more information, which will help you.
Thanks for your response sonukapoor. I have debug set to true on the .aspx page and both the user controls for this page and the same error as above is displayed.

Anymore ideas please?
As I can see in the stack you're using a database conneciton somewhere. Check what you're doing on line 44 of the common.ascx (see stack trace to find out which file it really is). An interesting post on-line is this: <a hef="http://www.error-bank.com/microsoft.public.dotnet.security/3764_Thread.aspx">http://www.error-bank.com/microsoft.public.dotnet.security/3764_Thread.aspx</a> which covers a similar situation where an Access db was used, causing security problems.
Yes this is correct I am using a Access database connection. There is no line 44 in common.ascx. The entire code for this .ascx file is

<%@. Control Language="C#" %>
<%@. import Namespace="DatabaseConnect" %>
<script runat="server"
void Page_Load(Object sender, EventArgs e) {

if(Session.IsNewSession)
{
DBConnect db = new DBConnect();
db.Main();

}

}

</script
This user control checks to see if it is a new session and if its a class is instansiated, a connection with an access database is made and data is read into variables. From what you are saying I would think the problem is with instansiating the class. Possibly I may not have sufficent permissions to instansiate a class, would this be possible?

Also I went through the link you gave and the instructions specified are not possible for me to do as I dont have admin permissions on the machine in question.
I think you need to print out that artical and give it to the admins at your school - they can make the changes. I'm sure you're not the first with this problem...
Thanks for all the help, I just emailed the administrator with the links and details.

Will report back soon.

If anyone else has any suggestions, please post as it is really important I get this sorted soon.

Serious problem with SQL database query (please help)

Hello, I have a serious problem dealing with database interrogation through SQL statements. To interrogate my database of employees by surname, I use the following code:


Dim mykeyword As String = txtKeyWord.Text
Dim MySQL as string = "Select * from employees WHERE surname = '" & mykeyword & "' Order by id_employee"

Dim myConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & server.mappath("employees.mdb") & ";")
Dim ds as DataSet=New DataSet()

Dim Cmd as New OleDbDataAdapter(MySQL,MyConn)
Cmd.Fill(ds,"employees")

myDataGrid.Datasource=ds.Tables("employees").DefaultView
myDataGrid.DataBind()
MyConn.Close()

Now, the problem arises when the user types one or more apostrophes (') in the TextBox for the keyword. The apostrophes interfere with the SQL string and the search simply fails.

I suppose I should check the content of the textbox before executing the query, to make sure there are no invalid characters, but I don't know how to look for a specific character in a string and replace it.

Besides, I think that it would be absurd to prevent the user from typing apostrophes because that character is so common that it would become a serious limitation.

I suppose I am not the first person who has encountered such a problem, so if you know the solution, please help me.

Thanks in advance.You can try:

Dim MySQL as string = "Select * from employees WHERE surname = '" & mykeyword.Replace("'","'+CHAR(39)+'") & "' Order by id_employee"
Also, this will help you to prevent SQL injections.
Usually replacing single apostrophe with pare, fixes the problem. Try

Dim MySQL as string = "Select * from employees WHERE surname = '" & mykeyword.Replace("'", "''") & "' Order by id_employee"


THANK YOU !!! Your help was great!

serious problem with VS.NET

When debugging codebehind in a test ASP.NET project, when I put a breakpoint
in a certain class, other breakpoints are automatically generated in another
file not in the project. This other file is part of a different project that
isn't even referenced in the first! What's up with that?

Paulnot sure what is going on but would suggest select clear all brake points,
rebuild and then
close .net and restart the computer, and restart .net and verify all brake
points are cleared. Then try to add one and see if it works.--
Paul G
Software engineer.

"PJ6" wrote:

> When debugging codebehind in a test ASP.NET project, when I put a breakpoint
> in a certain class, other breakpoints are automatically generated in another
> file not in the project. This other file is part of a different project that
> isn't even referenced in the first! What's up with that?
> Paul
>

serious problem with VS.NET

When debugging codebehind in a test ASP.NET project, when I put a breakpoint
in a certain class, other breakpoints are automatically generated in another
file not in the project. This other file is part of a different project that
isn't even referenced in the first! What's up with that?
Paulnot sure what is going on but would suggest select clear all brake points,
rebuild and then
close .net and restart the computer, and restart .net and verify all brake
points are cleared. Then try to add one and see if it works.--
Paul G
Software engineer.
"PJ6" wrote:

> When debugging codebehind in a test ASP.NET project, when I put a breakpoi
nt
> in a certain class, other breakpoints are automatically generated in anoth
er
> file not in the project. This other file is part of a different project th
at
> isn't even referenced in the first! What's up with that?
> Paul
>
>

Serious problems keeping an hold on database support in ASP.NET 2

ExecuteNonQuery requires an open and available Connection. The connection's
current state is closed.
Often, i mean a few times a day, the database is no longer reachable.
The appication pool must be reset to activate it again.
I believe after 30minutes it comes alive as well.
What is going on?
I can't find so now and then issues like this.How do you open the connection in the first place? It sounds like you
might be opening the connection once in your web app and leaving it
open...For better performance, you should be opening the Connection as
late as possible and closing it as soon as possible. A connection is an
expensive resource at both the client (web server) and database server
end, and built in connection pooling will help the creation and
disposal of these connections to be very fast.
I would write the code something like this:
' assuming the Command object has already been initialized,
' and its Connection property set
Try
cmd.Connection.Open
cmd.ExecuteNonQuery
Catch ex as Exception
' deal with the exception, or wrap it and throw it for someone else
to deal with
Finally
' Always try to close the connection, even if an exception has
occurred
Try
cmd.Connection.Close
Catch ex as Exception
' ignore any errors when attempting to close the connection
' it could already be closed
End Try
End Try
Mike
Edwin Knoppert wrote:
> ExecuteNonQuery requires an open and available Connection. The connection'
s
> current state is closed.
> Often, i mean a few times a day, the database is no longer reachable.
> The appication pool must be reset to activate it again.
> I believe after 30minutes it comes alive as well.
> What is going on?
> I can't find so now and then issues like this.
Xhead:
Some [minor] comments on your sample code.
1 - I see no reason to rethrow the exception, either deal with it (which
most people can't) or don't catch it at all. There's no advantage to
repackaging it.
2 - Your try inside the finally is dangerous. You are swallowing any
exceptions.. What if conenction.Close() caused an OutOfMemoryException or
ThreadAbortException? You should _never_ swallow exception unless you are
working in a global exception handler. Just check if it's closed and call
close (or better, check if it's nothing and called dispose). If the call to
dispose throws an exception, I'm ready to bet most applications would do
well to crash at this point.
Try
connection.Open
command.ExecuteNonQuery
Finally
if not connection is nothing then
connection.Dispose
end if
if not command is nothing then
command.Dispose
end if
end try
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"xhead" <xhead.ca@.gmail.com> wrote in message
news:1132601271.653323.241860@.g44g2000cwa.googlegroups.com...
> How do you open the connection in the first place? It sounds like you
> might be opening the connection once in your web app and leaving it
> open...For better performance, you should be opening the Connection as
> late as possible and closing it as soon as possible. A connection is an
> expensive resource at both the client (web server) and database server
> end, and built in connection pooling will help the creation and
> disposal of these connections to be very fast.
> I would write the code something like this:
> ' assuming the Command object has already been initialized,
> ' and its Connection property set
> Try
> cmd.Connection.Open
> cmd.ExecuteNonQuery
> Catch ex as Exception
> ' deal with the exception, or wrap it and throw it for someone else
> to deal with
> Finally
> ' Always try to close the connection, even if an exception has
> occurred
> Try
> cmd.Connection.Close
> Catch ex as Exception
> ' ignore any errors when attempting to close the connection
> ' it could already be closed
> End Try
> End Try
> Mike
> Edwin Knoppert wrote:
>
Thanks fellas, will try this tomorrow.
To me the garbage collection should fix this all imo.
Maybe my mistake.
Afaik the destroy of an object, should invoke any close as well isn't?
So the garbage collection terminating the object at some point should in
theory close the connections as well.
Maybe wishful thinking :)
Thanks,
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
schreef in bericht news:%23yl$hYt7FHA.3984@.TK2MSFTNGP11.phx.gbl...
> Xhead:
> Some [minor] comments on your sample code.
> 1 - I see no reason to rethrow the exception, either deal with it (which
> most people can't) or don't catch it at all. There's no advantage to
> repackaging it.
> 2 - Your try inside the finally is dangerous. You are swallowing any
> exceptions.. What if conenction.Close() caused an OutOfMemoryException or
> ThreadAbortException? You should _never_ swallow exception unless you are
> working in a global exception handler. Just check if it's closed and call
> close (or better, check if it's nothing and called dispose). If the call
> to dispose throws an exception, I'm ready to bet most applications would
> do well to crash at this point.
> Try
> connection.Open
> command.ExecuteNonQuery
> Finally
> if not connection is nothing then
> connection.Dispose
> end if
> if not command is nothing then
> command.Dispose
> end if
> end try
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
> "xhead" <xhead.ca@.gmail.com> wrote in message
> news:1132601271.653323.241860@.g44g2000cwa.googlegroups.com...
>
I have a related question.
I wrote me a wrapper which returns a reader, can i still safely close the
connection object?
The function returns the reader object as return value.
A declared(dim) reader receives this return refer and i use it further.
"Edwin Knoppert" <info@.pbsoft.speedlinq.nl> schreef in bericht
news:dltcuo$6ek$1@.azure.qinip.net...
> Thanks fellas, will try this tomorrow.
> To me the garbage collection should fix this all imo.
> Maybe my mistake.
> Afaik the destroy of an object, should invoke any close as well isn't?
> So the garbage collection terminating the object at some point should in
> theory close the connections as well.
> Maybe wishful thinking :)
> Thanks,
>
>
> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
> schreef in bericht news:%23yl$hYt7FHA.3984@.TK2MSFTNGP11.phx.gbl...
>
I believe this topic answers my questrion:
http://forums.asp.net/777619/ShowPost.aspx
Note that this part. forum has extensive faq's.
http://forums.asp.net/13/ShowForum.aspx
"Edwin Knoppert" <info@.pbsoft.speedlinq.nl> schreef in bericht
news:dlte6p$835$1@.azure.qinip.net...
>I have a related question.
> I wrote me a wrapper which returns a reader, can i still safely close the
> connection object?
> The function returns the reader object as return value.
> A declared(dim) reader receives this return refer and i use it further.
>
> "Edwin Knoppert" <info@.pbsoft.speedlinq.nl> schreef in bericht
> news:dltcuo$6ek$1@.azure.qinip.net...
>