473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,403 developers and data experts.

How to share code between .aspx pages

I don't know if there is a better way, but here is how I do it:

mypage.aspx:
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" AutoEventWireup="true" %>
  2. <%@ Import Namespace="System" %>
  3. <%@ Import Namespace="System.Web" %>
  4. <%@ Import Namespace="System.Data.OracleClient" %>
  5. <script runat="server" src="oralib.cs"></script>
  6. <html>
  7. <head><title>Reusable Code sample</title>
  8. </head>
  9. <body>
  10. <%
  11. OraLib ora = new OraLib(Request);
  12. if ( ora.HasOneRole("'IMAGE_UPLOAD'") ) {
  13.     %><H3>Welcome</H3>
  14. <%
  15. } else {
  16.     %><em><b><font color="red">UNAUTHORIZED</font></b></em>
  17. <%
  18. }
  19. ora.Close();
  20. %></body>
  21. </html>
  22.  
oralib.cs:
Expand|Select|Wrap|Line Numbers
  1. public class OraLib {
  2.     OracleConnection conn;
  3.     HttpRequest req;
  4.     bool isopen;
  5.  
  6.     public OraLib(HttpRequest hrq) {
  7.         req = hrq;
  8.         conn = new OracleConnection("user id=/;data source=myoradb;Integrated Security=true");
  9.         conn.Open();
  10.         isopen = true;
  11.     }
  12.  
  13.     public void Close() {
  14.         if ( isopen ) {
  15.             conn.Close();
  16.         }
  17.         isopen = false;
  18.     }
  19.  
  20.     public bool HasOneRole(String rol) {
  21.         String uid = req.ServerVariables["AUTH_USER"].ToUpper();
  22.         OracleCommand ocmd = conn.CreateCommand();
  23.         ocmd.CommandText = "select count(*) from dba_role_privs where grantee='"+uid+"' and granted_role in ("+rol+")";
  24.         OracleDataReader rows = ocmd.ExecuteReader();
  25.         int rval = 0;
  26.  
  27.         if ( rows.Read() ) {
  28.             rval = rows.GetInt32(0);
  29.         }
  30.         rows.Close();
  31.  
  32.         return (rval!=0);
  33.     }
  34. }
  35.  
Note:
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...
Sep 1 '13 #1
1 4631
Use QUERYSTRING to send data from 1 page to another
Feb 7 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: nospam | last post by:
I just read on Slash Dot about partial types. Now, is it possible to have a code behind split over two pages but still referencing the same .aspx file??? If so, that would be really nice as...
2
by: Asha Gill | last post by:
hello all how can i share variables between asp.net pages without using the session or anything that has got to do with the global file. can i use properties for this? 1 page calling the other to...
3
by: Joe | last post by:
Hi, I am new to creating .asp web sites and have a basic question. I have a website with .html pages running on an IIS server with .Net installed. I also have a couple of forms on the website....
2
by: Janusz Jezowicz | last post by:
Hello! I would like to have one page on the server, which would be a target processing page for a number of other aspx pages. E.g Processing page \portal_page.aspx Target pages
14
by: Mark B | last post by:
Our webhost (www.usbusinessweb.net) had a W2K IIS5 server crash after a scheduled hard-boot occurred during a ms-security patch install overnight. They couldn't get the server working again so they...
29
by: John Rivers | last post by:
Hello, What good reason there is for not allowing methods in ASPX pages I can't imagine, but here is how to get around that limitation: (START) <body MS_POSITIONING="FlowLayout"> <form...
3
by: stumay111 | last post by:
I am working in VS 2003, using VB.NET. I have a series of pages with forms on them, an application for a DOT number for motor carriers. The code behind them iterates through the controls on the...
3
by: Purti Malhotra | last post by:
Hi All, In our Web hosting environment we are using Virtual hosting i.e. multiple websites are on one server and multiple domains are pointing to a single website. Issue: We have two domains...
3
by: Aryan | last post by:
Hi, I have problem in creating Partial Class for ASPX pages. As my Codebase file for ASPX page is having more then 2500 lines of code. So its very hard to maintain the code. So I wanted to know,...
5
by: Arch Stanton | last post by:
I have a set of ASPX pages that work fine on my home computer (Vista), and on a server at work (XP). I just got a new laptop at work (XP) and these same files don't work on it. I installed IIS and...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.