473,405 Members | 2,210 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,405 software developers and data experts.

How to prevent direct browsing to a .asmx page?

All:

Pardon the newbie question, but let's say I've got two pages in my website:

Welcome.aspx
NoNav.aspx

I want users to be able to navigate to the welcome.aspx page (e.g.
http://myserver.com/Welcome.aspx), but I don't want them to be able to
navigate directly to NoNav.aspx. The NoNav.aspx page will be loaded only by
a menu selection in Welcome.aspx.

How do I disable direct navigation to NoNav.aspx in this example?

Thanks,
Bill
Sep 11 '06 #1
5 3212
Bill,

You could check the referrer using Request.UrlReferrer... which generally is
the page the user was looking at previous to the current request.

BUT... do not depend upon this... especially not for anything to do with
security (eg. no one can get to NoNav.aspx unless they come through
Welcome.aspx... so there for I don't need to check security.... no no no
no). It's very easy to fake the UrlReferrer. Also the referrer is an
optional field... and some requests just may not include it.

You could also use a cookie... though you'd have to set the cookie on
Welcome.aspx, clear the cookie on every other page. Seems like a lot of
work. Again... you can depend upon this.

Depending on what you're doing on the Welcome.aspx page you could have it
post back to NoNav.aspx. Have nonav.aspx check if page.previouspage is null
or not, and if not null if it was Welcome.aspx.

This one you might be ok depending on... if you protect the viewstate
(encrypting and mac address stuff).

All in all seems like any of the above are really fragile solutions and
generally hackish (gah! they are awful!!!!). You may want to redesign your
user interaction... what are you actually doing and why?

Regards,

Rob MacFadyen
"Bill Davidson" <Ra************@newsgroup.nospamwrote in message
news:u3**************@TK2MSFTNGP05.phx.gbl...
All:

Pardon the newbie question, but let's say I've got two pages in my
website:

Welcome.aspx
NoNav.aspx

I want users to be able to navigate to the welcome.aspx page (e.g.
http://myserver.com/Welcome.aspx), but I don't want them to be able to
navigate directly to NoNav.aspx. The NoNav.aspx page will be loaded only
by a menu selection in Welcome.aspx.

How do I disable direct navigation to NoNav.aspx in this example?

Thanks,
Bill

Sep 12 '06 #2
Hi Bill,

Besides Rob's input, you may also use a session state to indicate whether
or not it's navigated from Welcome.aspx:

protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
if (Menu1.SelectedValue == "New Item2")
{
Session["secretkey"] = true;
Response.Redirect("NoNav.aspx");
}
}

In NoNav.aspx:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["secretkey"] == null)
{
throw new Exception("You are not allowed to view this page
directly.");
}
else
{
Session.Remove("secretkey");
}
}
}

I hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 12 '06 #3

Bill Davidson wrote:
Pardon the newbie question, but let's say I've got two pages in my website:

Welcome.aspx
NoNav.aspx

I want users to be able to navigate to the welcome.aspx page (e.g.
http://myserver.com/Welcome.aspx), but I don't want them to be able to
navigate directly to NoNav.aspx. The NoNav.aspx page will be loaded only by
a menu selection in Welcome.aspx.

How do I disable direct navigation to NoNav.aspx in this example?
Set cookie (or session) in Welcome.aspx. Check in NoNav.aspx if
cookie/session is present. If not, redirect to Welcome.aspx.

--
BVH

Sep 12 '06 #4
Bill Davidson wrote:
All:

Pardon the newbie question, but let's say I've got two pages in my website:

Welcome.aspx
NoNav.aspx

I want users to be able to navigate to the welcome.aspx page (e.g.
http://myserver.com/Welcome.aspx), but I don't want them to be able to
navigate directly to NoNav.aspx. The NoNav.aspx page will be loaded only by
a menu selection in Welcome.aspx.

How do I disable direct navigation to NoNav.aspx in this example?

Thanks,
Bill
For some of our sites, we got downright paranoid about navigation. What
we do is, during page load, we call a function called CanNavigate(),
passing it the name of the current page. The CanNavigate function has
an array of valid from/to pairs. If the page passed in, and the
previous page, are a matching pair, we let the navigation happen, and
store the page passed in into a session variable (so that we can use
that as the previous page the next time the funtion is called).

We use the session so that this data stays in server land and cannot be
tampered with by an attacker. Other notes:

Navigating to the same page as the previous page is always allowed
(this allows postbacks to occur).

The From/To pairs are checked in both directions. This allows the back
button to be used (provided it causes a page request to occur).

If the known previous page doesn't match the referer header (as passed
to us by the user agent), we traverse the from/to pairs backwards, to
see if the user has pressed the back button and it hasn't caused a
postback. We can do this because our navigation hierarchy is treelike
(no "to" page can be reached from multiple "from" pages, except where
one "from" page is in the path of the other).

If we cannot match the referer header either to the known previous
page, nor to any parent of that page, we conclude that the navigation
is illegal.
>From all of the above, we're reasonably sure that the users are
following the navigation hierarchy we have determined. And if we cannot
match based on that data, we record the data with as much detail as
possible (for later analysis), and redirect to the root page.

I know for a fact that we do get some false negatives with this system
(where it decides the navigation is illegal even though it should have
been fine). If your projected user base can tolerate this, then it's
usable. Never really gotten to the bottom of this though (I think it
may be when the referer is unexpected)

Damien

Sep 12 '06 #5
Great responses; thanks to all four of you. I can see from the different
approaches that website navigation control is a non-trivial issue that can
get pretty involved especially on complex sites.

I do believe I have enough information to get me started.

Thanks Again !!!

Bill

"Bill Davidson" <Ra************@newsgroup.nospamwrote in message
news:u3**************@TK2MSFTNGP05.phx.gbl...
All:

Pardon the newbie question, but let's say I've got two pages in my
website:

Welcome.aspx
NoNav.aspx

I want users to be able to navigate to the welcome.aspx page (e.g.
http://myserver.com/Welcome.aspx), but I don't want them to be able to
navigate directly to NoNav.aspx. The NoNav.aspx page will be loaded only
by a menu selection in Welcome.aspx.

How do I disable direct navigation to NoNav.aspx in this example?

Thanks,
Bill

Sep 12 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Brearley | last post by:
I have a counter (alright one I found on asp101.com) that checks for a session variable to prevent the counter from incrmenting if a user refreshes the page or returns to the page during the same...
102
by: me | last post by:
How do I prevent the save/print/email/mypictures toolbar from popping up when IE users place their cursor over photos at my website? Thank you in advance for your help. Signed, me
3
by: Rob | last post by:
Each time a webform is posted back (submitted), another URL is added to the browser's history list. My web application allows a back button to return to previously visited pages, but I do not wish...
1
by: Craig G | last post by:
is there any implications of having more than one asmx page in your webservice i was intending to use a new asmx for each of my classes but a colleague in work says there is problems with this....
2
by: Dmitry Duginov | last post by:
I have a virtual directory where I allow browsing. When I implemented ISAPI filter for this directory (I deny access in some cases based on request headers), the contents of the directory are not...
5
by: Jon | last post by:
I am constantly getting reports in my task list like these: * 'someObjectName" is not a member of 'someOtherObjectName' * Handles clause requires a WithEvents variable. * Name 'someName' is not...
1
by: PeterW | last post by:
On my machine I developed a WebService on localhost and if I browse the asmx file I get the usual page that defines the webmethods exposed by the webservice and the opportunity to get the wsdl file...
3
by: Ben | last post by:
Hello I am in the final stages of developing my asp.net app and have a question. The app im creating has two frames, one being a menu and the other showing the detail. I would like to prevent...
2
by: yogarajan | last post by:
hi friends i have one problem. i m using forms authentication for my pages which consist of downloadable links (doc files, pdf files etc.,). the thing is, if i restrict access to the page, it...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.