最近看到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 初体验的更多相关文章

  1. Windows Azure初体验

    目前在IT界,云这个概念的第一意思不再是词典里的解释了.不过它们还是有相同点的——也许确实会酝酿出一块大蛋糕,可也是飘在天上,众神分食之,与我等P民无关.所谓云,不过是网络时代发展到一定阶段的必然产物 ...

  2. Windows Azure使用体验

    Windows Azure在今年6月6日由世纪互联代理在中国运营,目前只能体验,没有开放注册.不过,体验的门槛比较高,只对企业开放,未来大量对外开放使用貌似时间还早.大家都懂得,“国内门槛高”.本人在 ...

  3. Windows Azure 使用体验

    本文只是对Windows Azure的肤浅使用做个记录,算是简单入门吧. 一.门户网站 Windows Azure其实有两个版本,我们在国内所说的或者说所用的就是有别于国际版的,主要原因我想各位也是知 ...

  4. Windows Azure

    Windows Azure初体验 目前在IT界,云这个概念的第一意思不再是词典里的解释了.不过它们还是有相同点的——也许确实会酝酿出一块大蛋糕,可也是飘在天上,众神分食之,与我等P民无关.所谓云,不过 ...

  5. Windows Azure 免费初体验 - 创建部署网站

    前几天在看到有个学Windows Azure课程,送Windows Azure的活动,课程地址:http://www.microsoftvirtualacademy.com/ 在活得体验资格后,就迫不 ...

  6. Windows Azure 微软公有云体验(三) IIS中文编码解决方案

    Windows Azure 微软公有云已经登陆中国有一段时间了,现在是处于试用阶段,Windows Azure的使用将会给管理信息系统的开发.运行.维护带来什么样的新体验呢? Windows Azur ...

  7. Windows Azure 微软公有云体验(二) 存储成本比较分析

    Windows Azure 微软公有云已经登陆中国有一段时间了,现在是处于试用阶段,Windows Azure的使用将会给管理信息系统的开发.运行.维护带来什么样的新体验呢? Windows Azur ...

  8. Windows Azure 微软公有云体验(一) 网站、SQL数据库、虚拟机

    Windows Azure 微软公有云已经登陆中国有一段时间了,现在是处于试用阶段,Windows Azure的使用将会给管理信息系统的开发.运行.维护带来什么样的新体验呢? Windows Azur ...

  9. Windows Embedded Compact 7初体验

    Windows Embedded Compact 7初体验 Windows Embedded Compact 7已经出来半年多了,一直没时间搞.最近它又出了Refresh的版本,电脑也换了个1T的硬盘 ...

随机推荐

  1. eclipse插件大全(官方)

    eclipse插件大全:http://marketplace.eclipse.org/metrics/successful_installs 各个版本插件: http://download.eclip ...

  2. 深入探索C++对象模型(七)

    站在对象模型的尖端(On the Cusp of the Object Model) Template 下面是有关template的三个主要讨论方向: template的声明,基本上来说就是当你声明一 ...

  3. Linux查找后执行命令

    find . -name '*.jsp' -type f -print -exec rm -rf {} \; 在当前目录下找到jsp文件并删除.

  4. 「LibreOJ β Round #4」游戏

    https://loj.ac/problem/524 题目描述 qmqmqm和sublinekelzrip要进行一场游戏,其规则是这样的: 首先有一个序列,其中每个位置是一个整数或是X.双方轮流将X的 ...

  5. hdu 2121 Ice_cream’s world II

    Ice_cream’s world II http://acm.hdu.edu.cn/showproblem.php?pid=2121 Time Limit: 3000/1000 MS (Java/O ...

  6. SPOJ DQUERY 离线树状数组+离散化

    LINK 题意:给出$(n <= 30000)$个数,$q <= 2e5$个查询,每个查询要求给出$[l,r]$内不同元素的个数 思路:这题可用主席树查询历史版本的方法做,感觉这个比较容易 ...

  7. 【BZOJ】3173: [Tjoi2013]最长上升子序列(树状数组)

    [题意]给定ai,将1~n从小到大插入到第ai个数字之后,求每次插入后的LIS长度. [算法]树状数组||平衡树 [题解] 这是树状数组的一个用法:O(n log n)寻找前缀和为k的最小位置.(当数 ...

  8. 在iOS开发中如何播放视频

     技术博客http://www.cnblogs.com/ChenYilong/  新浪微博http://weibo.com/luohanchenyilong  如何播放视频 •iOS提供了叫做MPMo ...

  9. [CodePlus 2017 11月赛]晨跑 题解(辗转相除法求GCD)

    [CodePlus 2017 11月赛]晨跑 Description "无体育,不清华"."每天锻炼一小时,健康工作五十年,幸福生活一辈子".在清华,体育运动绝 ...

  10. 阿里iconfont引入方法

    原文:iconfont的引入方法   第一步:使用font-face声明字体@font-face {font-family: 'iconfont';src: url('iconfont.eot'); ...