![]() |
Web Development »
Web Security »
Security
Intermediate
Application Extension Mapping in a Shared Server Hosting EnviornmentBy FredParcellsProtect any file type in a certain folder with login. |
C#, XML, Windows, .NET 1.1, ASP.NET, IIS, VS.NET2003, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

My ISP told me I couldn't have Application Extension Mapping on a shared server hosting package. I can't afford a dedicated server so I put together this sample program to install on the ISP I was considering moving to. First I emailed a lot of Windows ISPs a Pre-Sales question: I need to add PDF extension to FileMapping so it will be processed by aspnet_isapi.dll. In my ASP.NET application I redirect all requests for PDF to a login screen. What's the most economical plan you have that can do this? See description here: MSDN. A few ISPs agreed to do it so I signed up with one. If the test program runs within the 30 day trial period, I am good to go. If not I get my money back and move down the list.
ASP.NET doesn't protect file extensions outside the ASP family. To do that you map an extension to the ASP executable in IIS. Use the Web.config file to tell your application the mode of authentication (Forms), what extension to watch for (.PDF), and who will handle it (MyHandler.dll). Write an HTTP handler to take the HTTP request and run it through the ASP executable (aspnet_isapi.dll). Web.config brings up Login.aspx.
More:
Open VS.NET: select New Project. Language: C#. Type: Web Application. Name: AppMapFileTest.
Label. Properties - Text: Welcome.
Label. Properties - Text: UserID.
Label. Properties - Text: Password.
TextBox. Properties - Text: txtUserId.
TextBox. Properties - Text: txtPassword.
Button. Properties - Text: Login, Name: cmdLogin.
<body MS_POSITIONING="GridLayout"> tag makes two hyper links:
<a href="example.pdf"target=_blank>Example Page</a>
<a href="scores/buynow.pdf"target=_blank>Buy Now</a> IHttpHandler. using System;
using System.Web;
namespace MyHandler
{
/// <summary>
/// Summary description for NewHandler.
/// </summary>
public class NewHandler : IHttpHandler
{
public NewHandler()
{
//
// TODO: Add constructor logic here
//
}
#region Implementation of IHttpHandler
public void ProcessRequest(System.Web.HttpContext context)
{
string FileName = context.Server.MapPath(context.Request.FilePath);
context.Response.WriteFile(FileName);
}
public bool IsReusable
{
get
{
return false;
}
}
#endregion
}
}
<authentication mode="Windows" /> to be: <authentication mode="Forms" >
<forms name=".reelbook" loginUrl="Login.aspx"/>
</authentication>
<system.web> and right before the </system.web> tag, add: <httpHandlers>
<add verb="GET" path="scores/*.pdf" type="MyHandler.NewHandler,MyHandler"/>
</httpHandlers>
</system.web> tag but before the </configuration> tag, add: <location path="scores">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
Hey! the OK button is all grayed out! After a long Google afternoon, I found this.
cmdLogin_Click method, add one line of code: FormsAuthentication.RedirectFromLoginPage(txtUserId.Text, false);
Run it. It doesn't like FormsAuthentication.
using statement: using System.Web.Security;.
Now it works. You have to login to get the Buy Now page.
A session cookie called reelbook named inside the <authentication mode="Forms" > tag of our Web.config is used so you don't have to login again until your next session. Only the folder set with the Add/Edit Application Extension Mapping dialog box will filter out PDF files to be processed by aspnet_isapi.dll. To prove this, right click on the default web site in the Internet Services Manager. Do steps 29) and 30). There's no PDF in the list which means that only the files in the folder you specified get sent to aspnet_isapi.dll. I don't think this will cause a performance problem in a shared hosting environment unless of course you get millions of hits for your valuable digital property. And if that's the case then you can afford to get a dedicated server in the first place. Anyway, my new ISP implemented this server-side tweak in less than an hour. I'm sure giving them this step by step page helped. You can never make too many friends in your ISP's Tech Support Group.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 11 Jul 2005 Editor: Smitha Vijayan |
Copyright 2005 by FredParcells Everything else Copyright © CodeProject, 1999-2009 Web22 | Advertise on the Code Project |