Protecting classic ASP pages with ASP.NET 2.0

G

Gert Conradie

I found a article on how to do this at:
http://www.oreillynet.com/windows/blog/2005/10/protecting_nonaspnet_resources.html

But could not get is working on my Windows XP Professional development
environment, that is confirmed by "To be clear, this does not work with
ASP.Net 2.0 on IIS5 " on
http://blogs.msdn.com/david.wang/archive/2005/08/29/HOWTO_Protect_non_dotNET_content.aspx

So I moved the application on a dev Win2003/iis6 environment - now I
get "The underlying connection was closed: The connection was closed
unexpectedly" exception.

Any ideas please?
This should be possible?

Thanks, gert

My web.config:
<httpModules>
<add name="gecHttpModule" type="myHttpModule.gecHttpModule"/>
</httpModules>
<httpHandlers>
<add path="*.asp" verb="GET,HEAD,POST"
type="System.Web.DefaultHttpHandler" validate="true"/>
</httpHandlers>

where gecHttpModule is my HttpModule that rewrite the url ONLY when a
certain key/value DONT occur in the querystring:
httpApp.Context.RewritePath(string.Format(@"~/FileViewerAsp.aspx?article={0}",
myPageNameRequested), false);

on FileViewerAsp.aspx:
private void displayArticle()
{
object o = Request.Params["article"];
if (o != null)
{
string pageName = o.ToString();

if (pageName.ToLower().EndsWith(".asp"))
{
pageName += @"?";
}

if (pageName.IndexOf(".asp") != -1)
{
if (!pageName.ToLower().EndsWith("?"))
pageName += @"&";

pageName += "ui2=true";
}

HttpWebRequest request;
StreamReader sr = null;
try
{
request = (HttpWebRequest)HttpWebRequest.Create(pageName);
request.Referer = "http://localhost";
request.PreAuthenticate = true;
request.AllowAutoRedirect = true;

request.ContentType = "text/html";
request.Timeout = 300000;

sr = new StreamReader(request.GetResponse().GetResponseStream());
string rawHtml = sr.ReadToEnd();


// Use regex to extract title and body
Regex reHtml = new
Regex(@"<title\b[^>]*>(?<Title>.*)</title\b[^>]*>.*<body>(?<Body>.*)</body>",
RegexOptions.IgnoreCase | RegexOptions.Singleline);
MatchCollection mc = reHtml.Matches(rawHtml);

if (mc.Count == 0)
throw new ApplicationException("Regex could not found correct tags");

this.Title = mc[0].Groups["Title"].Value;
LabelArticle.Text = mc[0].Groups["Body"].Value;

}
catch (Exception ex)
{
LabelArticle.Text += "Article not unavailable - " + ex.Message + "
StackTrace = " + ex.StackTrace;
}
finally
{
if (sr != null)
sr.Close();
}
}
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top