如何使用ASP.NET MVC实现站点而不使用Visual Studio?
|
我看过
ASP.NET MVC Without Visual Studio,
而接受的答案是,是的。 好的,下一个问题:怎么样? 这是一个类比。如果我想创建一个ASP.NET Webforms页面,我加载了my favorite text editor,创建一个名为Something.aspx的文件。然后我插入那个文件,一些样板: <%@ Page Language="C#"
Debug="true"
Trace="false"
Src="Sourcefile.cs"
Inherits="My.Namespace.ContentsPage"
%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Title goes here </title>
<link rel="stylesheet" type="text/css" href="css/style.css"></link>
<style type="text/css">
#elementid {
font-size: 9pt;
color: Navy;
... more css ...
}
</style>
<script type="text/javascript" language='javascript'>
// insert javascript here.
</script>
</head>
<body>
<asp:Literal Id='Holder' runat='server'/>
<br/>
<div id='msgs'></div>
</body>
</html>
然后我也创建Sourcefile.cs文件: namespace My.Namespace
{
using System;
using System.Web;
using System.Xml;
// etc...
public class ContentsPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Literal Holder;
void Page_Load(Object sender,EventArgs e)
{
// page load logic here
}
}
}
这是一个工作的ASPNET页面,在文本编辑器中创建。将其放入IIS虚拟目录中,它正在运行。 在文本编辑器中做什么,做一个基本的,你好的世界ASPNET MVC应用程序? (不带Visual Studio) 假设我想要一个具有控制器,一个视图和一个简单模型的基本MVC应用程序。我需要创建哪些文件,以及将会发生什么? 解决方法好的,我检查了 Walther’s tutorial,并有一个基本的MVC网站运行。需要的文件是: Global.asax App_CodeGlobal.asax.cs App_CodeController.cs ViewsHelloWorldSample.aspx web.config 而已。 在Global.asax中,我提供了这个样板: <%@ Application Inherits="MvcApplication1.MvcApplication" Language="C#" %> MvcApplication类在一个名为Global.asax.cs的模块中定义,它必须放在App_Code目录中。内容是这样的: using System.Web.Mvc;
using System.Web.Routing;
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",// Route name
"{controller}/{action}/{arg}",// URL with parameters
new { // Parameter defaults
controller = "HelloWorld",action = "Index",arg = "" } );
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
}
Controller.cs提供了处理各种请求的逻辑。在这个简单的例子中,控制器类是这样的: using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
public class HelloWorldController : Controller
{
public string Index()
{
return "Hmmmmm...."; // coerced to ActionResult
}
public ActionResult English()
{
return Content("<h2>Hi!</h2>");
}
public ActionResult Italiano()
{
return Content("<h2>Ciao!</h2>");
}
public ViewResult Sample()
{
return View(); // requires ViewsHelloWorldSample.aspx
}
}
}
Controller类必须命名为XxxxxController,其中Xxxxx部分定义了URL路径中的段。对于名为HelloWorldController的控制器,URL路径段是HelloWorld。 Controller类中的每个公共方法都是一个动作;当该方法名称包含在url路径中的另一个段中时,将调用该方法。因此,对于上述控制器,这些URL将导致调用各种方法: > http:// server / root / HelloWorld(默认的“action”) 每个方法返回一个Action结果,其中之一为:View(aspx页面),Redirect,Empty,File(各种选项),Json,Content(任意文本)和Javascript。 在这种情况下,View页面,如Sample.aspx,必须派生自System.Web.Mvc.ViewPage。 <%@ Page Language="C#" Debug="true" Trace="false" Inherits="System.Web.Mvc.ViewPage" %> 而已!将以上内容删除到IIS vdir中,给我一个工作的ASPNET MVC站点。 (嗯,我也需要web.config文件,其中有8k的配置All this source code and configuration is available to browse or download.) 然后我可以添加其他静态内容:js,css,图像和任何我喜欢的。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – 可在LAN中远程访问的IIS页面,但不能在服务器
- asp.net-mvc – 逐渐将现有的ASP.NET站点转换为MVC的最佳方
- ASP.NET c#获取屏幕宽度(以像素为单位)
- 在MVC 6中调整上传的图像大小
- 为什么我不能在我的代码asp.net c#中使用app_code中的代码文
- asp.net – Sys.WebForms.PageRequestManagerServerErrorEx
- asp.net-mvc – 将数据动态绑定到asp.net mvc中的下拉列表
- asp.net-mvc – 在Azure Active Directory B2C中按组授权
- Asp.Net Web Api基于令牌的授权,没有OWIN和AspNet.Identity
- 如何在ASP.NET中为不同的URL设置不同的超时
- asp.net-mvc-3 – HTML编码字符串 – ASP.NET We
- asp.net – 避免在web.config中提供服务器连接字
- asp.net-core – .net核心自定义身份验证中的Use
- VS 2015 CTP 6 Nuget Package Source
- IIS ASP.NET vs(NGINX FastCGI Mono或XSP)的性能
- ASP.NET-MVC.如何从URL获取控制器名称?
- asp.net – 如何使用GridView和ObjectDataSource
- asp.net – FileUpload.hasFile始终为False
- 在ASP.NET MVC中解码HTML 3
- asp.net-mvc – MVC4 RC WebApi参数绑定
