473,231 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

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 2414
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.Page 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.vadivelk.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_AuthenticateRequest 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_AuthenticateRequest, 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_AuthenticateRequest 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.Page 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.vadivelk.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_AuthenticateRequest, 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_AuthenticateRequest 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_AuthenticateRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated )
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
// Get Forms Identity From Current User
FormsIdentity id =
(FormsIdentity)HttpContext.Current.User.Identity;
// Get Forms Ticket From Identity object
FormsAuthenticationTicket 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.Current.User = new GenericPrincipal(id, roles);
}
}
}
}
// web.config:

<authentication mode="Forms">
<forms name="FormsAuthDB.AspxAuth"
loginUrl="default.aspx"
protection="All"
timeout ="10"
path="/"/>
</authentication>
<authorization>
<deny users="?" />
<allow users="*"/>
</authorization>

// loging page:

private void Button1_Click(object sender, System.EventArgs e)
{
// Initialize FormsAuthentication (reads the configuration and gets
// the cookie values and encryption keys for the given application)
FormsAuthentication.Initialize();

// Create connection and command objects
SqlConnection conn =
new SqlConnection("Data Source=PETER;Database=Northwind;User
ID=sa;password=;");
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT roles FROM Employees WHERE username=@username " +
"AND password=@password"; // this should really be a stored procedure,
right?

// Fill our parameters
cmd.Parameters.Add("@username", SqlDbType.NVarChar, 64).Value = TextBox1.Text;
cmd.Parameters.Add("@password", SqlDbType.NVarChar, 64).Value = TextBox2.Text;
FormsAuthentication.HashPasswordForStoringInConfig File(TextBox2.Text,"sha1");
// you can use the above method for encrypting passwords to be stored in the
database
// Execute the command
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
// Create a new ticket used for authentication
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, // Ticket version
TextBox1.Text, // Username to be associated with this ticket
DateTime.Now, // Date/time issued
DateTime.Now.AddMinutes(30), // Date/time to expire
true, // "true" for a persistent user cookie (could be a checkbox on form)
reader.GetString(0), // User-data (the roles from this user record in our
database)
FormsAuthentication.FormsCookiePath); // Path cookie is valid for

// Hash the cookie for transport over the wire
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName, // 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.Cookies.Add(cookie);

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

// Don't call the FormsAuthentication.RedirectFromLoginPage since it could
// replace the authentication ticket we just added...
Response.Redirect(returnUrl);
}
else
{
// Username and or password not found in our database...
ErrorLabel.Text = "Username / password incorrect. Please login again.";
ErrorLabel.Visible = 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_AuthenticateRequest, 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_AuthenticateRequest 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
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...
3
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...
5
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...
2
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...
2
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...
8
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...
10
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...
0
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...
0
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...
0
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...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.