简体   繁体   中英

ASP.Net without codebehind

I would like to create an ASP.Net page without all the codebehind and designer stuff. Basically I want to go back to ASP classic, but keep the CLR and Base Class Library that makes .Net oh-so-wonderful. I'd like just a page something like this:

<html>
<body>
<div>

  <%
    int customerID = Request.QueryString["CustomerID"];
    //Customer and DataAccess classes come from an extenal assembly
    Customer customer = DataAccess.GetCustomer(customerID); 
  %>
  You asked for Customer with ID: <%=customerID;%><br />
  Name: <%=customer.Name;%><br />
  Phone: <%=customer.Phone;%><br />


</div>
</body>
</html>

However there seem to be some problems with that.

  • The Request object is only available from within a Page object. I wish to completely delete the codebehind and designer pages.
  • No intellisense
  • Anything else I should be aware of before I get too deep into this?
  • No idea how to start pulling in extenal libraries

You don't need to do anything in code-behind if you don't want to.

To import namespaces, use an import directive:

<%@ Import namespace="System.Web" %>

To import external libraries, use an Assembly directive:

<%@ Assembly Name="YourAssemblyName" %>

Importing System.Web will allow you intellisense access to the HttpContext.Current.Request object. It will also give you intellisense for any other objects in that namespace, just like a code file.

I think your best bet is to look at ASP.NET MVC, specifically with the Razor View Engine.

You will still have some tooling around this though.

HttpContext.Current.Request将为您提供请求。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM