mypage.aspx:
Expand|Select|Wrap|Line Numbers
- <%@ Page Language="C#" AutoEventWireup="true" %>
- <%@ Import Namespace="System" %>
- <%@ Import Namespace="System.Web" %>
- <%@ Import Namespace="System.Data.OracleClient" %>
- <script runat="server" src="oralib.cs"></script>
- <html>
- <head><title>Reusable Code sample</title>
- </head>
- <body>
- <%
- OraLib ora = new OraLib(Request);
- if ( ora.HasOneRole("'IMAGE_UPLOAD'") ) {
- %><H3>Welcome</H3>
- <%
- } else {
- %><em><b><font color="red">UNAUTHORIZED</font></b></em>
- <%
- }
- ora.Close();
- %></body>
- </html>
Expand|Select|Wrap|Line Numbers
- public class OraLib {
- OracleConnection conn;
- HttpRequest req;
- bool isopen;
- public OraLib(HttpRequest hrq) {
- req = hrq;
- conn = new OracleConnection("user id=/;data source=myoradb;Integrated Security=true");
- conn.Open();
- isopen = true;
- }
- public void Close() {
- if ( isopen ) {
- conn.Close();
- }
- isopen = false;
- }
- public bool HasOneRole(String rol) {
- String uid = req.ServerVariables["AUTH_USER"].ToUpper();
- OracleCommand ocmd = conn.CreateCommand();
- ocmd.CommandText = "select count(*) from dba_role_privs where grantee='"+uid+"' and granted_role in ("+rol+")";
- OracleDataReader rows = ocmd.ExecuteReader();
- int rval = 0;
- if ( rows.Read() ) {
- rval = rows.GetInt32(0);
- }
- rows.Close();
- return (rval!=0);
- }
- }
on the .aspx page, you need to @Import the namespaces which the .cs files you include use. The example above, oralib.cs uses the OracleClient namespace so the .aspx imports those BEFORE the script src tag brings in oralib.cs.
I hope this helps someone, or if someone else has a better idea, feel free to comment...