473,799 Members | 3,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Http Module -Multiple Projects

Hi All,
i do hae a solution in which i do have mulitple projects
including Web Projects,, Depending on the functionality it gets
redirected to different web projects and it is working fine,
for eg: http:DomainName/MainProject/index.aspx, If i login, it gets
redirectes to a different Web Project inside the solution like
http://DomainName/MainProject/ChildProject/MyPage.aspx..

This works perfectly fine.

My issue is
:
I need to add redirect a set of request to a different page based on
some criteria, for eg; i do have certain calls like
http://DomainName/username, when a request come like this i need to
authenticate the username with the database and redirect to a
dynamically constructed page which can be a different Web Project
inside the same solution.
Can anyone please guide me how do i solve this issue, should i use a
HTTP Module for this: since it has multipl;e projects i guess some
thing wrong

Jul 12 '06 #1
6 2455
Preferably, you can make use of HttpModule and check the requested url
for the username whether it is authenticated or not. This is one way of
solving your problem.

But, I would suggest you to have a different approach which might well
fit in your case.

1. Have a class called "BasePage" which is inherited from
System.Web.UI.P age class.
2. Normally, all your WebForm classes would inherit the ASP.NET Page
class. You have to change that to "BasePage" class.
3. Now, implement your authentication logic inside the BasePage class by
overriding the Page_Load event.

If you implement the authentication code in HttpModule then you would
end up in checking for all the page requests even if you dont need to
authenticate a page. In this approach you have inherit the BasePage
class for the webform's that are needed to be authenticated.

Let me know if you have any issues in understanding this solution.

--
Vadivel Kumar
http://www.vadivelk.net
vadi@online#2.v adivelk.net (remove "online#2." )

thomson wrote:
Hi All,
i do hae a solution in which i do have mulitple projects
including Web Projects,, Depending on the functionality it gets
redirected to different web projects and it is working fine,
for eg: http:DomainName/MainProject/index.aspx, If i login, it gets
redirectes to a different Web Project inside the solution like
http://DomainName/MainProject/ChildProject/MyPage.aspx..

This works perfectly fine.

My issue is
:
I need to add redirect a set of request to a different page based on
some criteria, for eg; i do have certain calls like
http://DomainName/username, when a request come like this i need to
authenticate the username with the database and redirect to a
dynamically constructed page which can be a different Web Project
inside the same solution.
Can anyone please guide me how do i solve this issue, should i use a
HTTP Module for this: since it has multipl;e projects i guess some
thing wrong
Jul 12 '06 #2
In every page request, the Application_Aut henticateReques t even fires. This
is the typicaly place where you perform whatever authentication you want to
do .
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"thomson" wrote:
Hi All,
i do hae a solution in which i do have mulitple projects
including Web Projects,, Depending on the functionality it gets
redirected to different web projects and it is working fine,
for eg: http:DomainName/MainProject/index.aspx, If i login, it gets
redirectes to a different Web Project inside the solution like
http://DomainName/MainProject/ChildProject/MyPage.aspx..

This works perfectly fine.

My issue is
:
I need to add redirect a set of request to a different page based on
some criteria, for eg; i do have certain calls like
http://DomainName/username, when a request come like this i need to
authenticate the username with the database and redirect to a
dynamically constructed page which can be a different Web Project
inside the same solution.
Can anyone please guide me how do i solve this issue, should i use a
HTTP Module for this: since it has multipl;e projects i guess some
thing wrong

Jul 12 '06 #3

Hi,
if i implement the HTTP Module section, and use the
Application_Aut henticateReques t, will it fire for each and every
request between projects,
since i do have multiple Web Projects?

Regards

thomson

Peter Bromberg [ C# MVP ] wrote:
In every page request, the Application_Aut henticateReques t even fires. This
is the typicaly place where you perform whatever authentication you want to
do .
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"thomson" wrote:
Hi All,
i do hae a solution in which i do have mulitple projects
including Web Projects,, Depending on the functionality it gets
redirected to different web projects and it is working fine,
for eg: http:DomainName/MainProject/index.aspx, If i login, it gets
redirectes to a different Web Project inside the solution like
http://DomainName/MainProject/ChildProject/MyPage.aspx..

This works perfectly fine.

My issue is
:
I need to add redirect a set of request to a different page based on
some criteria, for eg; i do have certain calls like
http://DomainName/username, when a request come like this i need to
authenticate the username with the database and redirect to a
dynamically constructed page which can be a different Web Project
inside the same solution.
Can anyone please guide me how do i solve this issue, should i use a
HTTP Module for this: since it has multipl;e projects i guess some
thing wrong
Jul 12 '06 #4
I clearly understood ur solution i was using Base Page class Mechanism
to handle most of my validation usage, but what happens it still enters
my system, i dont want that i have to intercept t from the beginning
and redirect a different set all together,

I problem i noticed is that each and every time the request has to go
thru the authentication scheme.

Regards

thomson
Vadivel Kumar wrote:
Preferably, you can make use of HttpModule and check the requested url
for the username whether it is authenticated or not. This is one way of
solving your problem.

But, I would suggest you to have a different approach which might well
fit in your case.

1. Have a class called "BasePage" which is inherited from
System.Web.UI.P age class.
2. Normally, all your WebForm classes would inherit the ASP.NET Page
class. You have to change that to "BasePage" class.
3. Now, implement your authentication logic inside the BasePage class by
overriding the Page_Load event.

If you implement the authentication code in HttpModule then you would
end up in checking for all the page requests even if you dont need to
authenticate a page. In this approach you have inherit the BasePage
class for the webform's that are needed to be authenticated.

Let me know if you have any issues in understanding this solution.

--
Vadivel Kumar
http://www.vadivelk.net
vadi@online#2.v adivelk.net (remove "online#2." )

thomson wrote:
Hi All,
i do hae a solution in which i do have mulitple projects
including Web Projects,, Depending on the functionality it gets
redirected to different web projects and it is working fine,
for eg: http:DomainName/MainProject/index.aspx, If i login, it gets
redirectes to a different Web Project inside the solution like
http://DomainName/MainProject/ChildProject/MyPage.aspx..

This works perfectly fine.

My issue is
:
I need to add redirect a set of request to a different page based on
some criteria, for eg; i do have certain calls like
http://DomainName/username, when a request come like this i need to
authenticate the username with the database and redirect to a
dynamically constructed page which can be a different Web Project
inside the same solution.
Can anyone please guide me how do i solve this issue, should i use a
HTTP Module for this: since it has multipl;e projects i guess some
thing wrong
Jul 12 '06 #5
Hi Peter,
i tried with ur solution but its on a loop , Help me
out

Thanks in Advance

thomson
thomson wrote:
Hi,
if i implement the HTTP Module section, and use the
Application_Aut henticateReques t, will it fire for each and every
request between projects,
since i do have multiple Web Projects?

Regards

thomson

Peter Bromberg [ C# MVP ] wrote:
In every page request, the Application_Aut henticateReques t even fires. This
is the typicaly place where you perform whatever authentication you want to
do .
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"thomson" wrote:
Hi All,
i do hae a solution in which i do have mulitple projects
including Web Projects,, Depending on the functionality it gets
redirected to different web projects and it is working fine,
>
>
for eg: http:DomainName/MainProject/index.aspx, If i login, it gets
redirectes to a different Web Project inside the solution like
http://DomainName/MainProject/ChildProject/MyPage.aspx..
>
This works perfectly fine.
>
My issue is
:
>
>
I need to add redirect a set of request to a different page based on
some criteria, for eg; i do have certain calls like
http://DomainName/username, when a request come like this i need to
authenticate the username with the database and redirect to a
dynamically constructed page which can be a different Web Project
inside the same solution.
>
>
Can anyone please guide me how do i solve this issue, should i use a
HTTP Module for this: since it has multipl;e projects i guess some
thing wrong
>
>
Jul 12 '06 #6
How I did it, in ASP.NET 1.1:
//global.asax
protected void Application_Aut henticateReques t(Object sender, EventArgs e)
{
if (HttpContext.Cu rrent.User != null)
{
if (HttpContext.Cu rrent.User.Iden tity.IsAuthenti cated)
{
if (HttpContext.Cu rrent.User.Iden tity is FormsIdentity)
{
// Get Forms Identity From Current User
FormsIdentity id =
(FormsIdentity) HttpContext.Cur rent.User.Ident ity;
// Get Forms Ticket From Identity object
FormsAuthentica tionTicket ticket = id.Ticket;
// Retrieve stored user-data (our roles from db)
string userData = ticket.UserData ;
string[] roles = userData.Split( ',');
// Create a new Generic Principal Instance and assign to
Current User
HttpContext.Cur rent.User = new GenericPrincipa l(id, roles);
}
}
}
}
// web.config:

<authenticati on mode="Forms">
<forms name="FormsAuth DB.AspxAuth"
loginUrl="defau lt.aspx"
protection="All "
timeout ="10"
path="/"/>
</authentication>
<authorizatio n>
<deny users="?" />
<allow users="*"/>
</authorization>

// loging page:

private void Button1_Click(o bject sender, System.EventArg s e)
{
// Initialize FormsAuthentica tion (reads the configuration and gets
// the cookie values and encryption keys for the given application)
FormsAuthentica tion.Initialize ();

// Create connection and command objects
SqlConnection conn =
new SqlConnection(" Data Source=PETER;Da tabase=Northwin d;User
ID=sa;password= ;");
conn.Open();
SqlCommand cmd = conn.CreateComm and();
cmd.CommandText = "SELECT roles FROM Employees WHERE username=@usern ame " +
"AND password=@passw ord"; // this should really be a stored procedure,
right?

// Fill our parameters
cmd.Parameters. Add("@username" , SqlDbType.NVarC har, 64).Value = TextBox1.Text;
cmd.Parameters. Add("@password" , SqlDbType.NVarC har, 64).Value = TextBox2.Text;
FormsAuthentica tion.HashPasswo rdForStoringInC onfigFile(TextB ox2.Text,"sha1" );
// you can use the above method for encrypting passwords to be stored in the
database
// Execute the command
SqlDataReader reader = cmd.ExecuteRead er();
if (reader.Read())
{
// Create a new ticket used for authentication
FormsAuthentica tionTicket ticket = new FormsAuthentica tionTicket(
1, // Ticket version
TextBox1.Text, // Username to be associated with this ticket
DateTime.Now, // Date/time issued
DateTime.Now.Ad dMinutes(30), // Date/time to expire
true, // "true" for a persistent user cookie (could be a checkbox on form)
reader.GetStrin g(0), // User-data (the roles from this user record in our
database)
FormsAuthentica tion.FormsCooki ePath); // Path cookie is valid for

// Hash the cookie for transport over the wire
string hash = FormsAuthentica tion.Encrypt(ti cket);
HttpCookie cookie = new HttpCookie(
FormsAuthentica tion.FormsCooki eName, // Name of auth cookie (it's the
name specified in web.config)
hash); // Hashed ticket

// Add the cookie to the list for outbound response
Response.Cookie s.Add(cookie);

// Redirect to requested URL, or homepage if no previous page requested
string returnUrl = Request.QuerySt ring["ReturnUrl"];
if (returnUrl == null) returnUrl = "LoggedIn.aspx" ;

// Don't call the FormsAuthentica tion.RedirectFr omLoginPage since it could
// replace the authentication ticket we just added...
Response.Redire ct(returnUrl);
}
else
{
// Username and or password not found in our database...
ErrorLabel.Text = "Username / password incorrect. Please login again.";
ErrorLabel.Visi ble = true;
}
}

--Hope that helps.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"thomson" wrote:
Hi Peter,
i tried with ur solution but its on a loop , Help me
out

Thanks in Advance

thomson
thomson wrote:
Hi,
if i implement the HTTP Module section, and use the
Application_Aut henticateReques t, will it fire for each and every
request between projects,
since i do have multiple Web Projects?

Regards

thomson

Peter Bromberg [ C# MVP ] wrote:
In every page request, the Application_Aut henticateReques t even fires. This
is the typicaly place where you perform whatever authentication you want to
do .
Peter
>
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
>
>
>
>
"thomson" wrote:
>
Hi All,
i do hae a solution in which i do have mulitple projects
including Web Projects,, Depending on the functionality it gets
redirected to different web projects and it is working fine,


for eg: http:DomainName/MainProject/index.aspx, If i login, it gets
redirectes to a different Web Project inside the solution like
http://DomainName/MainProject/ChildProject/MyPage.aspx..

This works perfectly fine.

My issue is
:


I need to add redirect a set of request to a different page based on
some criteria, for eg; i do have certain calls like
http://DomainName/username, when a request come like this i need to
authenticate the username with the database and redirect to a
dynamically constructed page which can be a different Web Project
inside the same solution.


Can anyone please guide me how do i solve this issue, should i use a
HTTP Module for this: since it has multipl;e projects i guess some
thing wrong

Jul 12 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5378
by: Peter Gaunt | last post by:
I'm in the process of moving my site from one server to another (my old hosting company appears to have gone bust). On the old host and on my local Mac OS X machine I can send HTTP/1.1 response headers with no problem (e.g. header( 'HTTP/1.1 200 OK' ). If I do the same on the new server I get redirected to the server's 'Internal Error' page (i.e. error 500). No indication of what the error is.
3
2362
by: Mattias Holmlund | last post by:
Hi, I'm looking for a C#-module that can cache the results of HTTP-requests persistently on disk. I want to write a program that fetches data by issuing a number of HTTP-get requests and process the results. The data will only rarely change, so I would like to use module that issues proper ETag and If-Modified-Since http-headers to avoid downloading the data if it hasn't changed. I haven't been able to find such a module among the...
5
1813
by: Studio P.M. | last post by:
Having built successfully my first HTTP Module prototype (as for Q307996 - HOW TO: Create an ASP.NET HTTP Module ...) without really understanding what I've done, now I kindly ask this community for support to try and master this art; in the form of: - either a reference to a serious book comprehensively describing the matter; - or an answer to such a question as: What does it exactly mean, in C# terms, to implement the "IHttModule...
2
1411
by: Dave | last post by:
In KB article 308000 HOW TO: Create an ASP.NET HTTP Module Using Visual Basic .NET (http://support.microsoft.com/default.aspx?scid=kb;EN-US;308000), a simple HTTP Module is created which, among other things, raises a user defined event in the BeginRequest handler. it is defined as (in the HTTP Module Public Delegate Sub MyEventHandler(ByVal s As Object, ByVal e As EventArgs Public Event MyEvent As MyEventHandle and is handled in the...
2
2436
by: Norton | last post by:
I understand how to create HTTP modules that can be used to add functionality to a website but there are a few things I don't understand. If I create an HTTP Module and I want it to intercept a call to AuthenticateRequest, I know that in my init function for my HTTP module, I can add a handler to this method name and then use this event handler delegate to call my own function. I saw some sample code though that mentioned (for some...
8
24283
by: Andreas Klemt | last post by:
Hello, I get this error Message "cannot redirect after http headers have been sent" when I do this response.redirect ("home.aspx") How can I find out with vb.net if already a http header has been sent like If response.IsSentHttpHeader then ....
10
4254
by: Guoqi Zheng | last post by:
I know I can use http module in my asp.net project to rewrite url. However that is only true for .aspx page, there are many other static page in my application such as .htm. .asp, etc. My question is: 1. Is it possible to map all those request (.gif, .jpg, .swf, .asp, .htm, whatever) to my http module first? 2. Or in this situation, I have to use a ISAPI filter?
0
857
by: Sai | last post by:
Hi All, I have written a HTTP Module (Auth.dll) to authenticate pages in a virtual directory. The virtual directory points to a network path (per se \\net1\web). Now I have to place the compiled HTTP Module Auth.dll and supporting dll's in \\net1\web\bin folder, and copied the web.config to \\net1\web. I am getting security error when I try to access the pages from the virtual folder. If I remove the HTTP module it works fine.
0
1064
by: swigerb | last post by:
I have created an HTTP Module and an HTTP Handler. The HTTP Module is responsible for encrypting and decrypting all querystring parameters, which works fine. The HTTP Handler is to act as a proxy for calls to a specified CGI executable. Issue: As soon as I configure the Handler within the Web.Config file to run and begin debugging the Handler and Module...then access a "test.htm" page with an anchor tag containing a url with a...
0
1547
by: Cramer | last post by:
Using ASP.NET 3.5: Can a custom HTTP Module be used to register for the Application_Start event? Or _must_ I use Global.asax to work with Application.Start? I understand that I can use a custom HTTP Module to register for other pipeline events (like Application.BeginRequest), but I was told that the only place that I can set up an event handler for Application.Start is in Global.asax. My preference would be to register an HTTP Module...
0
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10237
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7567
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.