I hope there is some one that can help me spread some light on the situation.
I have the following code:
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;
///
/// This Class is used to determine weather or not the current user is logged in and allowed to view the page
/// which they are trying to access.
///
public abstract class base_Normal
{
public base_Normal()
{
string rawUrl = System.Web.HttpRequest.Request.RawUrl; //it tells me that it doesn't like this
//Error 1 'System.Web.HttpRequest' does not contain a definition for 'Request' C:\Websites\OryxSystems\App_Code\base_Normal.cs 19 49 C:\Websites\OryxSystems\
if (!(Global.OryxSession.IsAuthenticSession))
{
if (!(Global.OryxSession.UserType == Global.eUserType.Admin))
{
if (!(Global.OryxSession.UserType == Global.eUserType.Normal))
{
gblSettings.linkNumber = 4;
//This is where I wanna do a Response.Redirect("Login.aspx");
}
}
}
}
}
And every time I compile and try to run it, it gives me the error:
'System.Web.HttpRequest' does not contain a definition for 'Request'
Basically, what I am trying to do is see weather the user is logged in or not and then decide from there if they can acess the page. What will happen is that the page in question will then inherit this class. I have done this is a VB.NET website that I wrote and I am trying to get it to work in C# but I am going wrong.
I have tried a few different ways of getting around it but with no luck. If there is any one who can help me, please do and if you need any further examples ('for the session') then please do ask.
Thanks in advance.
Ricardo CarvalhoPosted Dec 19, 2007, 7:50 AM
public abstract class base_Normal : System.Web.UI.Page
{
public base_Normal()
{
string rawUrl = Request.RawUrl;
if (!(Global.OryxSession.IsAuthenticSession))
{
gblSettings.linkNumber = 4;
Response.Redirect("login.aspx?reminder=no&u=" + rawUrl);
}
else
{
if (!(Global.OryxSession.UserType == Global.eUserType.Admin))
{
if (!(Global.OryxSession.UserType == Global.eUserType.Normal))
{
gblSettings.linkNumber = 4;
Response.Redirect("falseusertype.aspx?usertype=Normal");
}
}
}
}
}
I changed my code to the above and at when I build it, it seems to succeed. I then inherit it in my new page like this:
public partial class about : base_Normal
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
And again, when I build it, it succeeds.
However, at runtime, I get the following error:
Request is not available in this context
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Web.HttpException: Request is not available in this context
Source Error:
So the way that I got around that was by changing the Request.RawUrl to HttpContext.Current.Request.RawUrl. That seemed to work fine for the request. Then I got an error on the Response. Which I then change to HttpContext.Current.Response.Redirect.
Thank you for your input.
AlanPosted Dec 19, 2007, 7:17 AM
'Request' (which returns an HttpRequest object) is in fact a property of the page.
So, for this to have a chance of working, I think your abstract base class will have to inherit from System.Web.UI.Page and then you'll need to replace this line:
string rawUrl = System.Web.HttpRequest.Request.RawUrl;
with this one:
string rawUrl = Request.RawUrl;
Incidentally, in C# you can't inherit from more than one class.