inaccessible type due to protection level

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

New to C# programming.

I'm trying to implement some simple security in my website.
Basically a user cannot surf to secured aspx pages simply by accessing them
directly through the address bar. If they have not logged in and created a
forms authentication cookie they will be redirected to a friendly page
telling them the page is inaccessible.

I'm putting my code: (in the global.ascx.cs file)

public void Application_AuthenticateRequest(Object sender, EventArgs e)
{
//executes upon attempting to authenticate the user.

//Extract the forms authentication cookie.

string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = new System.Web.HttpCookie();
authCookie = Request.Cookies[cookieName];

}

more code follows but this is where the error is.

on compiliation:
error: System.Web.HttpCookie(); is inaccessible due to its protection level.
the new keyword is underlined blue.

I tried changing the scope of a number of things all of which are likely a
breach of security anyways (since the shell code for global.ascx is
automatically generated by visual studio), and they don't work.

thanks

Chris
 
Hi,

New to C# programming.

I'm trying to implement some simple security in my website.
Basically a user cannot surf to secured aspx pages simply by
accessing them directly through the address bar. If they have
not logged in and created a forms authentication cookie they
will be redirected to a friendly page telling them the page is
inaccessible.

I'm putting my code: (in the global.ascx.cs file)

public void Application_AuthenticateRequest(Object sender,
EventArgs e) {
//executes upon attempting to authenticate the user.

//Extract the forms authentication cookie.

string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = new System.Web.HttpCookie();
authCookie = Request.Cookies[cookieName];

}

more code follows but this is where the error is.

on compiliation:
error: System.Web.HttpCookie(); is inaccessible due to its
protection level. the new keyword is underlined blue.

I tried changing the scope of a number of things all of which
are likely a breach of security anyways (since the shell code
for global.ascx is automatically generated by visual studio),
and they don't work.

Chris,

First, the System.Web.HttpCookie() constructor isn't public, nor is
it documented. If you want to create a cookie, use one of the
documented constructors for HttpCookie. In .Net 1.1, the two
documented constructors take one or two string arguments.

Second, if you want to get a reference to a cookie in
Request.Cookies, there is no need to create a cookie first. To
retrieve a cookie, this should work:

string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Request.Cookies[cookieName];
 
Back
Top