468,785 Members | 1,730 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,785 developers. It's quick & easy.

inaccessible type due to protection level

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
Nov 17 '05 #1
1 2090
"=?Utf-8?B?Q2hyaXM=?=" <Ch***@discussions.microsoft.com> wrote in
news:AA**********************************@microsof t.com:
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];

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by BlueOysterCult | last post: by
3 posts views Thread by tshad | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.