How to create a web framework in C# without ASPX?
Asked Answered
S

5

6

I've managed to get a C# asp page running under ubuntu/apache/mono, but I don't want to write my framework in these ASP pages, I want to use straight C# and then I'll use a templating language for my views. But I don't know where to begin?

C# is a compiled language, so... how would I do this? Would I compile everything and then have apache hook into the (single) executable and pass in the the request URL? Could I request specific .cs pages and then have apache tell it to compile and then "display" it only if it's been updated? Can the "view" files be compiled individually to avoid having to recompile everything every time there's a change? Is there some "base" I can work from, or am I going to have to reinvent accessing GET and POST variables (by reading header info) and all sorts of other stuff we take for granted in languages like PHP?

Servia answered 29/5, 2010 at 23:49 Comment(0)
N
3

AFAIK there's no reason you can't do what you want on top of the ASP.NET core, using things like HttpApplication, HttpHandler etc. For example, you could route all URLs to a single HttpHandler and take it from there manually.

I suggest taking a look at how ASP.MVC does it - create a new ASP.NET MVC project in MonoDevelop, look at the Global.asax.cs, open the Web.config and look at the custom http handlers and modules it registers. ASP.NET MVC is OSS so you can dig around in that too.

Nambypamby answered 1/6, 2010 at 16:54 Comment(1)
Ahh... excellent. I've been trying to figure out what the bare bones needed for an ASP.net application were. I think this will work.Servia
G
1

If you're really adverse to using ASP at all, you could try reading the source code for ASP and see how they implement the features you're going to need, like accessing POST and GET information, routing, session management, etc.

However, that will be a tonne of work. What you could do is implement the vast majority of your logic in c# class libraries, and just use ASP to "host" the application, and pass through the data you require.

Gracegraceful answered 30/5, 2010 at 0:11 Comment(3)
It's not really the ASP "engine" I'm averse to, I'm mostly just not fond of the syntax. If I could use ASP but avoid the .asp pages, this is a possibility.Servia
AFAIK, getting classic ASP to run outside of an IIS environment is a much taller order than ASP.NET.Maidstone
Sorry I figured it wAs taken for granted that the discussion was in reference to asp.netGracegraceful
T
1

Nobody asks you to put heavy code in ASPX pages. (Please don't use ASP, which is another thing).

In ASP.NET WebForms model, you can use Code Behind mode.

In ASP.NET MVC model, you have much more control over nearly all aspects.

Therefore, spare some time and dive into the existing models. Trying to roll out your own can be a waste of time.

Mono supports both models.

Besides, ASP.NET was designed in a way different to PHP, and you should know that introduces differences who cannot always meet your requirements above.

Tripodic answered 30/5, 2010 at 0:19 Comment(3)
I'm aiming for a cross between Django and RoR. I'll have to delve deeper into this stuff to see if I can really bend it to meet my needs. I thought ASP.NET MVC already was a framework? I don't want to be forced to use any of their paradigms. I want full control over how and when each view function/action is called, what gets passed to it, what should be returned, which template should be loaded... I want to write my own URL router, etc. etc. I've done it in PHP before, but w/ PHP you still get all the magic global variables. I'm fine passing around some sort of "request" object...Servia
...if necessary, like Python/Django (mod_wsgi??) does. Just trying to figure out where to start/what to build off.Servia
Impressed. Well, then probably you should utilize Apache and some part of Mono to build your own ASP.NET model. :)Tripodic
M
1
  1. You said ASP. Is this ASP or ASP.NET pages you've gotten working? Big difference.
  2. Can you access Request/Response in the ASP.NET pages, if so, you should be able to get at the GET/POST.
  3. Do you know how to build what you are trying in normal IIS/ASP.NET? If not, please save yourself some sanity and get it at least roughly working there first. That's just the general advice to reduce the number of variables/unknowns you are working with at a time.
  4. Ultimately, you're building your own handlers. I imagine you will need to have some bit of dll that will see the request for page xxx, read that page, and instantiate the backing class. A look at the asp.net mvc source may help lots (under additional downloads).
Maidstone answered 30/5, 2010 at 0:20 Comment(1)
1. Uh.. I dunno. What is the difference? I've got a single index.aspx page which I can view under localhost... 2. Err.. I should be able to. 3. No, not a clue :) I've used plain old PHP, PHP w/ Cake, and Python/Django. I'm assuming the concepts should be transferable to C#. Why should I build it in ASP.NET too?Servia
M
1

There are a lot of alternate templating languages available for ASP .NET MVC, see this question for a loooong list: ASP.NET MVC View Engine Comparison

Microscopium answered 30/5, 2010 at 0:36 Comment(3)
Well it's not just the templating language. I've found with every framework I've used, they all have pros and cons, but they all do something in a way I really hate. I'd like to build one my way, even if no one ever uses it.Servia
Well, given that you're working in C#, start with ASP .NET MVC, which is both nice and open-source, with one of those template engines, and start evolving it in a direction you want to go. That way you start from something that works, and can respond to issues you find as you develop something usefulMicroscopium
I should add, if you want something like Django or RoR, ASP .NET MVC plus Fluent NHibernate plus a better template engine is pretty much there already. It doesn't force you into anything much, and like I said, it's open-source so if you don't like something you can change it.Microscopium

© 2022 - 2024 — McMap. All rights reserved.