Wednesday, May 28, 2008

Authorization deny anonymous and running locally doesn’t load stylesheet for login page

A developer I know ran into this situation that he built this simple app with default page and login page. He has lot of data files that the default page servers but he wanted to limit the access to only authorized users. Suggested him to look into the built in authentication and authorization modules and it worked fine on the server by setting the authorization as:

<authorization>

<deny users="?"/>

<allow users="*"/>

</authorization>

However, when he ran the app from visual studio, locally, the login page doesn't load the stylesheets or any images. Took me couple of seconds to realize that the difference is when he runs locally, all the files including images and styles are served by the built in dev server which applies the authorization rules to every file. And hence the styles and images are not loaded.

Typically, we design the default page and login pages with no authorization and so may not realize this issue. But when we get into such situation, the solutions could be quite simple too. Either pick the files and/or folders to authorize and apply to them only. Or, exclude generic folders like images and styles. For example,

<location path="images">

<system.web>

<authorization>

<allow users="*"/>

</authorization>

</system.web>

</location>

Love coding!

Thursday, May 22, 2008

Oracle CLOB Search – how to find a string pattern using where clause

Came across a need to search Oracle clob content for particular words pattern and was wondering how to do it. Well, it's simple using DBMS_LOB package. The where clause would look like:

Where DBMS_LOB.instr(myClobColumn, 'my data pattern here') > 0

For more info on usage, refer here.

Love coding!

Wednesday, May 7, 2008

Oracle 10g Namespace for child nodes when using Table(XMLSequence

When parsing or looping through each node of XML document, in C#, we know that the namespace gets associated with each child node. While using Oracle 9i XmlType and getting a table list of child nodes using Table(XMLSequence( concept, the child nodes doesn't carry the name space as the parent xml. However, migrating to 10g recently I came across failures in some procedures that try to parse the xml and upon debugging figured out that the namespace is indeed carried in child nodes; just like how we see in .Net. Here's a test to figure out the difference.

Try this SQL on both 9i and 10g:

Select Value(P) EachProduct

From Table(XMLSequence(XMLTYPE('<?xml version="1.0" encoding="utf-16"?>'||

'<myTestXML xmlns="http://www.myTestXML.com">'||

' <Product>'||

' <ID>P001</ID>'||

' <Description>Test 001</Description>'||

' <Price>12.00</Price>'||

' </Product>'||

' <Product>'||

' <ID>P002</ID>'||

' <Description>Test 002</Description>'||

' <Price>13.00</Price>'||

' </Product>'||

'</myTestXML>').Extract('//Product', 'xmlns="http://www.myTestXML.com"'))) P;


And check the results (just posting the first row):
9i:

<Product>

<ID>P001</ID>

<Description>Test 001</Description>

<Price>12.00</Price>

</Product>


10g
:

<Product xmlns="http://www.myTestXML.com">

<ID>P001</ID>

<Description>Test 001</Description>

<Price>12.00</Price>

</Product>


So, to use the child node, we need to make sure that the namespace is considered in extracting values.

Love coding!