473,624 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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"?>
<configuratio n>
<appSettings/>
<connectionStri ngs/>
<system.web>
<httpModules>
<add type="Syska.Err ors.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.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

namespace Syska.Errors
{
public class Admin : IHttpModule
{
public void Init(HttpApplic ation app)
{
app.BeginReques t += new EventHandler(ap p_BeginRequest) ;
app.Error += new EventHandler(ap p_Error);
}

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

void app_BeginReques t(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 2392
Hi

Did you mean this ?


using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

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

#region IHttpModule Members

public void Init(HttpApplic ation app)
{
app.BeginReques t += new EventHandler(ap p_BeginRequest) ;
app.Error += new EventHandler(ap p_Error);
}

void app_Error(objec t sender, EventArgs e)
{

}

void app_BeginReques t(object sender, EventArgs e)
{
if
(HttpContext.Cu rrent.Request.R awUrl.ToLower() .Contains("/admin/"))
HttpContext.Cur rent.Response.R edirect("~/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"?>
<configuratio n>
<appSettings/>
<connectionStri ngs/>
<system.web>
<httpModules>
<add type="Syska.Err ors.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.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

namespace Syska.Errors
{
public class Admin : IHttpModule
{
public void Init(HttpApplic ation app)
{
app.BeginReques t += new EventHandler(ap p_BeginRequest) ;
app.Error += new EventHandler(ap p_Error);
}

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

void app_BeginReques t(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.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

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

#region IHttpModule Members

public void Init(HttpApplic ation app)
{
app.BeginReques t += new EventHandler(ap p_BeginRequest) ;
app.Error += new EventHandler(ap p_Error);
}

void app_Error(objec t sender, EventArgs e)
{

}

void app_BeginReques t(object sender, EventArgs e)
{
if
(HttpContext.Cu rrent.Request.R awUrl.ToLower() .Contains("/admin/"))
HttpContext.Cur rent.Response.R edirect("~/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
2130
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) Implements IHttpModule.Init httpApp = context
4
1634
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
1920
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 http module was included in the root site which is GRSCS and the webservice has not functioned ever since. the service starts working when u comment the httpmodule section in the web.config file of the main (root application) which is GRSCS. Is...
3
2175
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 declared of course into the Webconfig. This application runs perfect. So, i created another application (Accreditation), that runs perfect too inside of it as a virtual directory that does not use HttpModule. Now i am getting this error....
9
2711
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): System.Collections.Specialized.NameValueCollection SectionIndex = (System.Collections.Specialized.NameValueCollection)System.Configuration.ConfigurationSettings.GetConfig("Rewrite.NET/Index"); The value always returns me null, and just to check it was...
1
3195
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 virtual directory. The apps are not related. Old app web.config has: <httpModules> <add name="a" type="foo.a, foo" /> <add name="b" type="bar.b, bar" />
2
2347
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 pages. In order to try to do this I have added the following test code in our web.config file. <location path="Login.aspx"> <system.web>
0
4660
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 http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx. In Vista when I press F5 or Control F5 I get an error message saying HTTP Error 500.19 - Internal Server Error Description: The requested page cannot be accessed because the related...
5
2434
by: =?Utf-8?B?TUNN?= | last post by:
What do the following httpModules do? UrlAuthorization FileAuthorization ServiceModel ErrorHandlerModule ScriptModule
0
8238
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8174
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,...
0
8680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7164
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6111
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
5565
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
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1485
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.