Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 29th, 2010, 04:15 PM
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default Building a C++ style web server app in C#?

My understanding is that programming with webforms like I am now sends the request through any and all of the application's HttpModules, then routes the request through an HttpHandler (possibly a custom .ashx) and a text file (the .aspx page) in order to generate a response. Any correction on this would be appreciated if I'm wrong.

I would like to play with a concept I've heard the C++ guys do, just using C#. Can I simply grab the HttpRequest and build the HttpResponse directly, maybe using an HTTP Module or MVC??? I'd like to experiment taking a request for a URL like http://www.myapp.com/subfolder/subfolder2/thispage.aspx, parse the URL and HTTP headers for input, draw in application logic code and database data, and construct the HTTP response without ever having a physical file "thispage.aspx" sitting in subfolder2.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
  #2 (permalink)  
Old June 29th, 2010, 04:26 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

You need to write an HTTP handler (IHttpHandler) and map it to your URL / extension. Here's a random tutorial http://www.brainbell.com/tutorials/A...tpHandler.html but many more exist,

For the record: the "text file" is more or less coincidence. It's actually an IHttpHandler (the Page class) that is responsible for processing the request.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
chroniclemaster1 (July 1st, 2010)
  #3 (permalink)  
Old July 1st, 2010, 04:41 PM
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Yes! Thank you very much.

I'm working up a test page, and I think it would make the most sense to keep the convention of the .aspx extension. I see no reason to change it, and since the beta site is on shared hosting, I don't think I'm allowed to remap any extensions in IIS anyway. However, this looks like it would break all my existing pages. If my pseudocode looks like this...

Code:
Retrieve URL of request

Search for URL in DB

if the URL exists in the DB (ie it's my new test)
     // DO STUFF

else
     // attempt to serve the old page normally
My decision-making code will short circuit the normal process so I can play around, but how do I code the ELSE so that every other page on my website doesn't die?
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
  #4 (permalink)  
Old July 2nd, 2010, 02:52 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You don't have to remap URLs in IIS, you can remap them in web.config. For example, you can create an HTTP Handler (.ashx extension) with this code:
Code:
 
public class MyHandler : IHttpHandler
{
  public void ProcessRequest(HttpContext context)
  {
    context.Response.ContentType = "text/plain";
    context.Response.Write("Hello World");
  }
 
  public bool IsReusable
  {
    get
    {
      return false;
    }
  }
}
You can then remap existing URLs to this new handler in web.config:

Code:
 
<urlMappings enabled="true">
  <add url="~/SomeUrl.aspx" mappedUrl="~/MyHandler.ashx"/>
</urlMappings>
So, I would only remap the exceptions to your own HttpHandler and not all extensions which then requires you to try and find out what your code can handle and then give the rest back to the framework.

Alternatively, if you still want to do it from your own handler (not recommended), you can do something like this in ProcessRequest of the IHttpHandler:

Code:
 
if (someCondition)
{
  string virtualPath = "~/Default.aspx";
  string physicalPath = context.Server.MapPath(virtualPath);
  IHttpHandler handler = PageParser.GetCompiledPageInstance(virtualPath, physicalPath, context);
  handler.ProcessRequest(context);
  context.ApplicationInstance.CompleteRequest();
}
Be aware of a few issues though: first: this new ProcessRequest will probably trigger your handler again which will call ProcessRequest which will trigger your handler which will call , well, I think you get the idea. You need to code some stuff to avoid that.

Also, not 100%, but there might be some issues with regard to caching when you execute pages like this. You may want to read up on IHttpHandler and IHttpHandlerFactory if you continue down this path.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQl Server license for a web server app carlos890 SQL Server 2000 1 December 8th, 2005 12:42 PM
HyperLink web server control style acko ASP.NET 1.0 and 1.1 Basics 2 November 14th, 2003 02:55 PM
Permissions for Web app. files on Web server Jan_Ma Classic ASP Basics 0 June 28th, 2003 02:06 PM
Permissions for Web app. files on server Jan_Ma All Other Wrox Books 0 June 28th, 2003 02:02 PM



All times are GMT -4. The time now is 01:22 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.