473,383 Members | 1,792 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,383 software developers and data experts.

Web.Config and httpmodules

Hi,

Google gives alot of hits on httpmodules but I can't seem to find any
useful on my problem ...

I have a site where I'm using my own auth system ... ( guess it could be
better but its work, maybe I will make a new one later, or use the build
-in )

But to my problem ... I have a Admin area, but that users dont have
access to ... So I wanted to make a httpmodule that checked a Session
variable to see if the user had a high enough level to get access to the
admin area ... but I can't get it working:

I have tried many thing in the Web.Config file ...
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<httpModules>
<add type="Syska.Errors.Admin" name="Admin" />
</httpModules>
</system.web>
</configuration>

This file is placed in the "/admin" folder on the site ...
So all the normal request dont get parsed in this module ...

My Class:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Syska.Errors
{
public class Admin : IHttpModule
{
public void Init(HttpApplication app)
{
app.BeginRequest += new EventHandler(app_BeginRequest);
app.Error += new EventHandler(app_Error);
}

void app_Error(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}

void app_BeginRequest(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}

public void Dispose() { }
}
}

And none of the above get executed ...

Am I doing somewrong here ?

best regards
Mikael Syska
Mar 5 '07 #1
2 2379
Hi

Did you mean this ?


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for Admin
/// </summary>
public class Admin :IHttpModule
{
public Admin()
{
//
// TODO: Add constructor logic here
//
}

#region IHttpModule Members

public void Init(HttpApplication app)
{
app.BeginRequest += new EventHandler(app_BeginRequest);
app.Error += new EventHandler(app_Error);
}

void app_Error(object sender, EventArgs e)
{

}

void app_BeginRequest(object sender, EventArgs e)
{
if
(HttpContext.Current.Request.RawUrl.ToLower().Cont ains("/admin/"))
HttpContext.Current.Response.Redirect("~/Login.aspx");
}

public void Dispose() { }
#endregion
}


--
-------------------------------------------
אם תשובה זו עזרה לך, א*א הצבע "כן"

If my answer helped you please press "Yes" bellow

Adlai Maschiach
http://blogs.microsoft.co.il/blogs/adlaim/
"Mikael Syska" wrote:
Hi,

Google gives alot of hits on httpmodules but I can't seem to find any
useful on my problem ...

I have a site where I'm using my own auth system ... ( guess it could be
better but its work, maybe I will make a new one later, or use the build
-in )

But to my problem ... I have a Admin area, but that users dont have
access to ... So I wanted to make a httpmodule that checked a Session
variable to see if the user had a high enough level to get access to the
admin area ... but I can't get it working:

I have tried many thing in the Web.Config file ...
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<httpModules>
<add type="Syska.Errors.Admin" name="Admin" />
</httpModules>
</system.web>
</configuration>

This file is placed in the "/admin" folder on the site ...
So all the normal request dont get parsed in this module ...

My Class:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Syska.Errors
{
public class Admin : IHttpModule
{
public void Init(HttpApplication app)
{
app.BeginRequest += new EventHandler(app_BeginRequest);
app.Error += new EventHandler(app_Error);
}

void app_Error(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}

void app_BeginRequest(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}

public void Dispose() { }
}
}

And none of the above get executed ...

Am I doing somewrong here ?

best regards
Mikael Syska
Mar 5 '07 #2
Hi,

Yahhh, kind a ...

But with that code ... are you saying that its impossible to plug a
httpmodule in a Web.Config file in a subdirectory of a site ... ?

/Web.Config
/Admin/Web.Config

Cause right now I can only get it to read the httpmodules in the root
Web.Config file ... not the one in the "Admin" folder ....

No errors what so ever ...

Read about other that tried to remove httpmodule witch very impossible
due to some I cant remember atm ...

// ouT

Adlai Maschiach wrote:
Hi

Did you mean this ?


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for Admin
/// </summary>
public class Admin :IHttpModule
{
public Admin()
{
//
// TODO: Add constructor logic here
//
}

#region IHttpModule Members

public void Init(HttpApplication app)
{
app.BeginRequest += new EventHandler(app_BeginRequest);
app.Error += new EventHandler(app_Error);
}

void app_Error(object sender, EventArgs e)
{

}

void app_BeginRequest(object sender, EventArgs e)
{
if
(HttpContext.Current.Request.RawUrl.ToLower().Cont ains("/admin/"))
HttpContext.Current.Response.Redirect("~/Login.aspx");
}

public void Dispose() { }
#endregion
}

Mar 5 '07 #3

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

Similar topics

2
by: Simon-Pierre Jarry | last post by:
Hi, I created a custom HttpModule for managing the security of my application. in "Init" sub, I regsiter the events doing that : Public Sub Init(ByVal context As System.Web.HttpApplication)...
4
by: Bill Long | last post by:
Hi, I have a situation like this: wwwroot has a web.config file that adds a custom http module <httpModules> <add name="MyModue" type="MyType,MyAssembly" /> </httpModules>
1
by: Asela Gunawardena | last post by:
Hi all, we have a webservice as a seperate virtual directory placed under a Web Site named GRSCS in IIS. Both are .NET applications and uses MS application blocks as the data layer. Recently an...
3
by: Jose Fernandez | last post by:
HI first of all, excuse me for my english. And Thank in advance for even read my post. I have a problem that is driving me insane. I have an application (JUCAR) which use HttpModule and i have...
9
by: Milsnips | last post by:
Hi all. i'm tryng to implement the Rewrite.NET url rewritining functionality into a test project i've created, however i am hitting a problem at this line (direct from the web example): ...
1
by: Samuel R. Neff | last post by:
We have a problem with Web.config inheritance in two of our applications. We have an old app which is poorly written and must be in the root of the server. We have a newer app which runs from a...
2
by: alexvodovoz | last post by:
Hi, I have been struggling with this for the past couple of days. We have a custom http module setup in our project to filter some requests. I only want this module to be applied to certain...
0
by: mazdotnet | last post by:
Hi, I'm using UrlRewriter.NET in my project which is causing problems when in Vista (same code works fine on Windows XP). I'm going by the example in Scott's Blog...
5
by: =?Utf-8?B?TUNN?= | last post by:
What do the following httpModules do? UrlAuthorization FileAuthorization ServiceModel ErrorHandlerModule ScriptModule
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.