首页 文章 精选 留言 我的

精选列表

搜索[asp.net],共1052篇文章
优秀的个人博客,低调大师

CentOS+Nginx+Supervisor部署ASP.NET Core项目

对.Net Core的学习和实践,已经进行了一年多的世间,截止目前,微软已经发布.Net Core2.1,关于.NetCore的应用部署的文章比比皆是。今天借此,回顾下.net core环境的部署过程。 首先,我这边采用的是CentOS7+上的版本,.net core2.1。在动手前,我们先做这样的思考 如何部署一个正式的.net core2.1项目? 解决方案有: 1、利用.net core runtime及.net core sdk,将编译好的项目,发布至服务器上,然后运行dotnet application.dll命令。 这样程序就运行起来,但是要想让.net core程序进程一直存在,就需要做其它方面的工作了,比如网上介绍的比较多的supervisor守护进程服务,这样可以保证.net core程序,在终端关闭后,仍然可以运行。 2、利用跨平台服务器Jexus。 3、利用docker容器技术,让.net core程序运行在docker容器中。 当然,这里肯定还有其它解决方案,比如Nancy之类的,这里不做进一步的阐述了。 接下来,我们就针对,第一种方式,采用python开发的supervisor服务,来守护.net core进程。 然后,我们再想了,当守护进程安装配置完成后,我们再安装一个web服务器,如nginx作为.net core程序的代理服务器。 于是得出,此次实践中,我们分别需要,安装配置.net core、supervisor、nginx等,那接下来,我们就分别针对这三种环境的配置,进行介绍: 1、.net core的安装,这个可以在官方网站找到进一步的说明https://www.microsoft.com/net/learn/get-started-with-dotnet-tutorial 首先是下载软件包: sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm 然后,通过yum命令来进行.net core sdk的安装(安装sdk时.net core运行时也一并被安装了)。 sudo yum install dotnet-sdk-2.1 等待安装完成即可。通过dotnet --info/--version命令可以查看版本信息。 [root@cce9311ee74bc4f27afe8f58e5e0b5021-node2 ~]# dotnet --info.NET Command Line Tools (2.1.101) Product Information: Version: 2.1.101 Commit SHA-1 hash: 6c22303bf0 Runtime Environment: OS Name: centos OS Version: 7 OS Platform: Linux RID: centos.7-x64 Base Path: /usr/share/dotnet/sdk/2.1.101/ Microsoft .NET Core Shared Framework Host Version : 2.0.6 Build : 74b1c703813c8910df5b96f304b0f2b78cdf194d这样.net core2.1环境就安装好了。 2、supervisor服务的安装。 这个具体参考我的另一篇博客 https://my.oschina.net/lichaoqiang/blog/1861791 3、NGINX的安装 这里,我们是直接通过yum命令来安装的。 首先是下载了软件包管理 通过yum来安装nginx yum -y install nginx 启动nginx服务 systemctl start nginx.service systemctl enable nginx.service 默认,nginx配置文件在/etc/nginx/目录下。命令进入/etc/nginx/conf.d文件夹,为我们的.net core应用程序创建一个配置文件 server { listen 80; server_name www.demo.com; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { proxy_pass http://localhost:5000; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } 然后重新加载 配置文件: 完成以上三步后,我们supervisorctl restart 应用程序.dll即可。 最后,通过vs的发布功能,发布我们的.net core项目,避免nuget引用包导致的问题,这里我们发布的时候,目标运行时选linux-x64。 关于.net core部署正式环境,就介绍到这里。

优秀的个人博客,低调大师

Asp.net MVC2.0系列文章-添加操作

创建数据模型Model 数据模型主要包括数据信息、验证规则以及业务逻辑。 创建Model的方式有多种,可以使用微软的ADO.NET Entity Data Model,也可以使用第三方工具生成实体对象,对于比较简单的实体,我们可以手工添加,此处就是手动敲上去的。 分析:此处定义了新闻实体对象的的一些属性,在每个Property上都存在一些注解,比如字段Title上RequiredAttribute,表明Title栏位是必填字段,如果不填写会显示错误信息”请输入标题!” DataTypeAttribute属性表明此字段的数据类型为文本类型,它是个枚举类型集合,如下: Member name Description Custom Represents a custom data type. DateTime Represents an instant in time, expressed as a date and time of day. Date Represents a date value. Time Represents a time value. Duration Represents a continuous time during which an object exists. PhoneNumber Represents a phone number value. Currency Represents a currency value. Text Represents text that is displayed. Html Represents an HTML file. MultilineText Represents multi-line text. EmailAddress Represents an e-mail address. Password Represent a password value. Url Represents a URL value. ImageUrl Represents a URL to an image. 这些类型,可以分别试试,看看最终效果什么样子的。 DisplayNameAttribute属性表明了此字段要文字说明。 创建View视图 MVC提供了生成View的向导工具,很方便的,如下图流程步骤: 我们在View文件夹下,新建一个新文件夹,命名为News 右击News文件夹,选择Add->AddView功能菜单,出现如下界面: 在View name栏位,我可以给此视图修改名称,比如AddNews, 选中Create a strongly-typed view栏位,选择刚才定义的实体类Model,并选择View content栏位为Create操作。 其他栏位默认值就OK 最终效果如下图所示: 单击【Add】按钮,即可添加AddNews.aspx视图成功。此文件的核心代码如下所示: <asp:ContentID="Content2"ContentPlaceHolderID="MainContent"runat="server"> <h2> 添¬¨ª加¨®新?闻?</h2> <%using(Html.BeginForm()) {%> <%:Html.ValidationSummary(true)%> <fieldset> <legend>新?闻?</legend> <divclass="editor-label"> <%:Html.LabelFor(model => model.Title)%> </div> <divclass="editor-field"> <%:Html.TextBoxFor(model => model.Title)%> <%:Html.ValidationMessageFor(model => model.Title)%> </div> <divclass="editor-label"> <%:Html.LabelFor(model => model.CreateTime)%> </div> <divclass="editor-field"> <%:Html.TextBoxFor(model => model.CreateTime,new{ @class ="date"})%> <%:Html.ValidationMessageFor(model => model.CreateTime)%> </div> <divclass="editor-label"> <%:Html.LabelFor(model => model.Content)%> </div> <divclass="editor-field"> <%:Html.EditorFor(model => model.Content)%> <%:Html.ValidationMessageFor(model => model.Content)%> </div> <p> <inputtype="submit"value="添¬¨ª加¨®"/> </p> </fieldset> <%}%> <div> <%:Html.ActionLink("Back to List","Index","Home")%> </div> </asp:Content> 分析: 在日期文本框中,新增加属性new{ @class ="date"}),此Class属性是为了稍后的日历控件的显示。要使日期文本框显示日期控件,可以使用Jquery UI,方法是: 1/、Jquery UI官方网站http://www.jqueryUI.com下载最新的UI类库 2、添加日历控件的CSS文件和JS文件到项目中,如下图 3、在母版页面Site.Master中添加JS的引用,以及页面初始化时绑定日历控件到文本框,代码如下: <linkhref="http://www.cnblogs.com/Content/jquery.ui.all.css"rel="stylesheet"type="text/css"/> <scriptsrc="http://www.cnblogs.com/Scripts/jquery-1.4.1.min.js"type="text/javascript"></script> <scriptsrc="http://www.cnblogs.com/Scripts/jquery-ui-1.8.2.custom.min.js"type="text/javascript"></script> <scripttype="text/javascript"> $(document).ready(function() { $("input:text.date").datepicker( { dateFormat:"yy-mm-dd" }); }); </script> 到此,日历栏位的文本框就可以显示日历控件了,稍后看效果图。 创建Controller文件 在Controllers文件夹下,新增News文件夹; 单击右键,选择Add->Controller,显示如下界面 重命名Controller Name栏位为NewsController,同时选择下方的复选框,最终效果如下图: 单击【Add】按钮,自动产生Controller中的一些方法,这时候对Controller中的方法做一些修改,即可完成添加新闻页面初始化的方法,以及添加新闻功能,代码如下: // GET: /News/Create //完成页面初始化 publicActionResultAddNews() { returnView(); } // // POST: /News/Create //完成添加按钮事件 [HttpPost] publicActionResultAddNews(THelperMVC.Models.News.AddNewsModelnews) { if(ModelState.IsValid) { newsService.AddNews(); returnRedirectToAction("index","Home"); } else { ModelState.AddModelError("","请?输º?入¨?合?法¤¡§的Ì?信?息¡é!ê?"); } returnView(news); } 至此,MVC的各个层次都已经创建完,让我们看看最终的效果吧。 程序效果图 本文转自灵动生活博客园博客,原文链接:http://www.cnblogs.com/ywqu/archive/2010/06/24/1764062.html ,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册