Windows Azure 初体验
最近看到windows azure 在做活动,只需花一块钱就可以体验一个月的windows azure. 于是,我就注册了一个账号也尝试一把云时代,传送门。 注册很简单的,成功后可以看到这个界面。
然后,我就研究了一下怎么把网站发布到云上,在此分享一下。网站是简单的基于asp.net mvc + code first 比较简单。
首先新建一个asp.net mvc 的网站。在此我命名为 WindowsAzureMVC,为了支持code first 需要添加entity framework 的dll。右键管理NUGET程序包 添加EntityFramework.
在web.config 文件中添加节点:
<connectionStrings>
<add name="TestConnect" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=Test;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False" providerName="System.Data.SqlClient" />
</connectionStrings>
再新建一个AzureDataContext类
public class AzureDataContext : DbContext
{
public AzureDataContext()
: base("name=TestConnect")
{ } public DbSet<User> User { get; set; }
} public class User
{
public Guid Id { get; set; } public string Name { get; set; } public int Age { get; set; }
}
这个就是简单的数据了,表示一个数据库有一个表叫做User。
然后运行nuget命令 先打开Nuget 控制台 视图-》其他窗口-》程序包管理器控制台。
输入Enable-Migrations 会自动生成一个Configuration类
internal sealed class Configuration : DbMigrationsConfiguration<WindowsAzureMVC.Data.AzureDataContext>
{
public Configuration()
{
AutomaticMigrationDataLossAllowed = true;
AutomaticMigrationsEnabled = true;
} protected override void Seed(WindowsAzureMVC.Data.AzureDataContext context)
{
context.User.AddOrUpdate(p => p.Id, new User() { Id = Guid.NewGuid(), Age = , Name = "test" }); }
}
我在seed 方法中加了一个初始化数据。
然后输入 update-database 命令,成功之后 会看到生成的数据库。
然后我在 MVC的controller 和view 里写了一些简单的代码。
public ActionResult Index()
{
User user = new Data.User() { Id = Guid.NewGuid(), Name = "test", Age = new Random().Next(, ) }; azureDataContext.User.Add(user);
azureDataContext.SaveChanges();
List<User> userList = azureDataContext.User.ToList(); return View(userList);
}
@model List<WindowsAzureMVC.Data.User>
@{
ViewBag.Title = "Home Page";
}
<div class="row">
<table class="table table-bordered">
<caption>用户列表</caption>
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@item.Name
</td>
<td>
@item.Age
</td>
</tr>
}
</tbody>
</table>
</div>
OK, 网站这边基本完成,比较简单的演示。
然后发布,首先我需要新建一个数据库,
然后新建一个网站,
之后我需要下载发布配置文件,
下载的文件名叫justtest.chinacloudsites.cn.PublishSettings 之后就可以发布了,
右键 -》 发布
点击发布成功。地址是 http://justtest.chinacloudsites.cn/
基本搞定收工。这就是我的azure 初体验。
Windows Azure 初体验的更多相关文章
- Windows Azure初体验
目前在IT界,云这个概念的第一意思不再是词典里的解释了.不过它们还是有相同点的——也许确实会酝酿出一块大蛋糕,可也是飘在天上,众神分食之,与我等P民无关.所谓云,不过是网络时代发展到一定阶段的必然产物 ...
- Windows Azure使用体验
Windows Azure在今年6月6日由世纪互联代理在中国运营,目前只能体验,没有开放注册.不过,体验的门槛比较高,只对企业开放,未来大量对外开放使用貌似时间还早.大家都懂得,“国内门槛高”.本人在 ...
- Windows Azure 使用体验
本文只是对Windows Azure的肤浅使用做个记录,算是简单入门吧. 一.门户网站 Windows Azure其实有两个版本,我们在国内所说的或者说所用的就是有别于国际版的,主要原因我想各位也是知 ...
- Windows Azure
Windows Azure初体验 目前在IT界,云这个概念的第一意思不再是词典里的解释了.不过它们还是有相同点的——也许确实会酝酿出一块大蛋糕,可也是飘在天上,众神分食之,与我等P民无关.所谓云,不过 ...
- Windows Azure 免费初体验 - 创建部署网站
前几天在看到有个学Windows Azure课程,送Windows Azure的活动,课程地址:http://www.microsoftvirtualacademy.com/ 在活得体验资格后,就迫不 ...
- Windows Azure 微软公有云体验(三) IIS中文编码解决方案
Windows Azure 微软公有云已经登陆中国有一段时间了,现在是处于试用阶段,Windows Azure的使用将会给管理信息系统的开发.运行.维护带来什么样的新体验呢? Windows Azur ...
- Windows Azure 微软公有云体验(二) 存储成本比较分析
Windows Azure 微软公有云已经登陆中国有一段时间了,现在是处于试用阶段,Windows Azure的使用将会给管理信息系统的开发.运行.维护带来什么样的新体验呢? Windows Azur ...
- Windows Azure 微软公有云体验(一) 网站、SQL数据库、虚拟机
Windows Azure 微软公有云已经登陆中国有一段时间了,现在是处于试用阶段,Windows Azure的使用将会给管理信息系统的开发.运行.维护带来什么样的新体验呢? Windows Azur ...
- Windows Embedded Compact 7初体验
Windows Embedded Compact 7初体验 Windows Embedded Compact 7已经出来半年多了,一直没时间搞.最近它又出了Refresh的版本,电脑也换了个1T的硬盘 ...
随机推荐
- Codeforces 895.B XK Segments
B. XK Segments time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- springboot如何集成mybatis的pagehelper分页插件
mybatis提供了一个非常好用的分页插件,之前集成的时候需要配置mybatis-config.xml的方式,今天我们来看下它是如何集成springboot来更好的服务的. 只能说springboot ...
- STL源码分析-内存分配器
http://note.youdao.com/noteshare?id=744696e5f6daf0f2f03f10e381485e67
- count distinct
SELECT COUNT(DISTINCT Customer) AS NumberOfCustomers FROM Orders
- OpenCV---边缘保留滤波EPF
OpenCV经典的两种实现EPF方法:高斯双边和均值迁移 一:双边模糊 差异越大,越会完整保留 def bi_demo(image): dst = cv.bilateralFilter(image,0 ...
- centos 7 pdo
在windows本机上测试好的Thinkphp5代码部署到centos7阿里云主机上面就提示class pdo not found,网上搜索了一大堆终于解决了.不过隔了这么几个小时详细的步骤就有些忘记 ...
- cmd窗口关闭 -----window小技巧!
前沿 平时开发的时候经常用到windows 的命令行工具来启动程序 或是 查看本地数据库的信息 : 经常的手动关闭 ,对于我这种,能用键盘完成的就坚决不用鼠标的人是多么痛苦. 所以在此罗列了一些命 ...
- Windows API函数大全(精心总结)
WindowsAPI函数大全(精心总结) 目录 1. API之网络函数... 1 2. API之消息函数... 1 3. API之文件处理函数... 2 4. API之打印函数... 5 5. ...
- 课程设计——利用信号量实现哲学家进餐问题(JAVA)
package cn.Douzi.PhiEat; /** * 表示筷子的类 */ public class Chopstick{ /** * 表示筷子是否可用 */ private volatile ...
- Dijkstra算法:POJ No 3268 Silver Cow Party
题目:http://poj.org/problem?id=3268 题解:使用 priority_queue队列对dijkstra算法进行优化 #include <iostream> #i ...