Web.Config and httpmodules

M

Mikael Syska

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
 
G

Guest

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().Contains("/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/
 
M

Mikael Syska

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top