471,120 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,120 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 2296
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Bill Long | last post: by
3 posts views Thread by Jose Fernandez | last post: by
1 post views Thread by Samuel R. Neff | last post: by
reply views Thread by mazdotnet | last post: by
5 posts views Thread by =?Utf-8?B?TUNN?= | last post: by

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.