Application_AuthorizeRequest

M

MCM14

I use the Sub Application_AuthorizeRequest in the application pipeline to do
some custom page authorization. Basically I check the page requested and
redirect to the Login page if needed. The problem is, every single request
gets sent through here, including static files like .css. Is there a way for
me to configure this to only trigger when a .aspx file is requested?
 
S

Shengqing Yang [MSFT]

Hi MCM14,

Based on my understanding, you got the problem that the
Application_AuthorizeRequest checks all the requests including static files
like .css file and .js file. As far as I know, this issue only occurs when
we are debugging the website via ASP.NET development server of Visual
Studio.

As we know, the module that ASP.NET development server holds is different
from the one working with IIS. It makes all the requests of files go
through its application pipeline. But when the site is published to IIS,
only the requests to the specified file extensions will access the
application pipeline. This list can be found and edited in IIS.

I made a test demo to illustrate this phenomenon just using a blank ASP.NET
page linking a .css file and some simple code in
Application_AuthenticateRequest function.

//ASP.NET page

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebApplication1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<link rel="Stylesheet" href="Stylesheet1.css" />
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

//Application_AuthenticateRequest function in Global.asax.cs

protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
using (StreamWriter sw = new
StreamWriter(Server.MapPath("~/log.txt"),true,System.Text.Encoding.Default))
{

sw.Write(Request.Url.ToString() + "\r\n");
}
}

When we debug this page via Visual Studio, the log.txt will be appended
info like this:

http://localhost:6402/Default.aspx
http://localhost:6402/Stylesheet1.css
http://localhost:6402/favicon.ico

But after we publish the site to IIS 7 and run it again, the log.txt will
only have info like:

http://localhost/default.aspx


--
Sincerely,
Bravo Yang
Microsoft Online Support

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 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. 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/en-us/subscriptions/aa948874.aspx

==================================================
 
M

MCM14

Thank you. That is very helpful. Can you tell me where in IIS that extension
list is located?
 
S

Shengqing Yang [MSFT]

Hi MCM14,

You can find the list by the steps below.

For IIS6:

1. Open Internet Information Services (IIS) from Administrative Tools in
Control Panel.
2. Select your website from the Web Sites tree node and right click it to
open the Properties dialog window.
3. Go to Home Directory tab and click the Configuration Button in
Application Settings frame.

For IIS7:

1. Open Internet Information Services (IIS) from Administrative Tools in
All Control Panel Items.
2. Select your website from the Web Sites tree node.
3. Double click the Handler Mappings icon from the IIS frame in the main
page of window.

--
Sincerely,
Bravo Yang
Microsoft Online Support

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 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. 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/en-us/subscriptions/aa948874.aspx

==================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top