473,385 Members | 1,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2212
"=?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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BlueOysterCult | last post by:
Hello I can't get around the error "inaccessible due to its protection level" - it points at a line that I am using .Sort() and BinarySearch() - but the real problem lies in another part of the...
1
by: Larry | last post by:
Thanks in advanced for your help I've added a TextBox1 and Button1 to a form in C# in VS.net 2003. When I double click on the Button1 at design time, a private method ButtonClick. I've...
1
by: Larry | last post by:
I have a VB background and am developing a new windows app in Csharp. I'm getting the error. 'inaccessible due to its protection level' I've added a TextBox1 and a Button1 to a form. I...
3
by: tshad | last post by:
I am getting a message for my objects that say: testNulls.cs(13,33): error CS0122: 'FtsData.IntType.IntType()' is inaccessible due to its protection level I have a class calling objects out of...
2
by: Jason Shohet | last post by:
I have a line: public System.Web.UI.HtmlControls.HtmlTable bldgInfo; Even though its public, for some reason every so often, .NET tells us that bldgInfo table is inaccessible due to the...
1
by: Arjen | last post by:
Hi, I have this inside a webusercontrol: private string MenuItem = new string; Inside the .ascx file I do this: <%= MenuItem(0) %> And I get this error: ....is inaccessible due to its...
2
by: sck10 | last post by:
Hello, I am getting the following error: fvServiceIdea_ItemUpdating_Validate(object, System.Web.UI.WebControls.FormViewUpdateEventArgs)' is inaccessible due to its protection level. Below...
5
by: Iain | last post by:
Hi All I have the code below (Using Delphi 2006 Developer to create an C# ASP.Net page to update a simple database table. When the page is fired I get the following error message ...
6
by: milund | last post by:
I have a "funny" after upgrading to .NET2.0. The following code is placed inside an unsafe method in assembly "A" System.Object myIUnknownObject =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.