How to create a web framework in C# without ASPX?
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 r开发者_如何学JAVAequest 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?
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.
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.
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.
- You said ASP. Is this ASP or ASP.NET pages you've gotten working? Big difference.
- Can you access Request/Response in the ASP.NET pages, if so, you should be able to get at the GET/POST.
- 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.
- 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).
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
精彩评论