我可以专门使用 ASP.NET MVC3 作为 RESTful Web 服务吗?

发布于 2024-11-11 14:12:23 字数 332 浏览 0 评论 0原文

我正在构建一个只读

我们使用 Vimeo 托管所有视频,我想将 Vimeo 视频以及 RSS 源集成到我们的网络应用程序中。

应用程序中的其余“内容”将是静态“信息”以及联系表单。

我的问题是,仅使用 ASP.NET MVC3(减去“V”)将 JSON 驱动到我们的 Web 应用程序是否合理?

I'm building a READ ONLY app for our local church.

We use Vimeo to host all of our videos, and I'd like to integrate our Vimeo vids as well as our RSS feed into our web app.

The rest of the "content" in the app will be static "info" as well as a contact form.

My question is, is it kosher to ONLY use ASP.NET MVC3 (minus the "V") to drive the JSON to our web app?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乜一 2024-11-18 14:12:23

是的,这很好用。只需返回一个 JsonResult 即可。

这是我在生产中使用的一个示例:

 public partial class StudentController : BaseController {
    public StudentController(RESTContext portalContext)
        : base(portalContext) { }

    [HttpGet, Url("organizations/{organizationId?}/students")]
    public virtual JsonResult List(Guid? organizationId) {
        if (organizationId != RESTContext.OrganizationId)
            throw new HttpNotAuthorizedException();

        var query = RESTContext.GetQuery<IQuery<StudentCasesReport>>()
            .Where(x => x.OrganizationId, organizationId)
            .OrderBy(x => x.LastName, SortOrder.Ascending);
        var cases = query.Execute(IsolationLevel.ReadUncommitted);

        return Json(cases, JsonRequestBehavior.AllowGet);
    }

    [HttpGet, Url("organizations/{organizationId?}/students/{studentId?}")]
    public virtual JsonResult Get(Guid? organizationId, Guid? studentId) {
        if (studentId.IsNull())
            throw new HttpNotFoundExecption();

        if (organizationId != RESTContext.OrganizationId)
            throw new HttpNotModifiedException();

        var query = RESTContext.GetQuery<IQuery<StudentCasesReport>>()
            .Where(x => x.OrganizationId, organizationId)
            .Where(x => x.StudentCaseId, studentId)
            .OrderBy(x => x.LastName, SortOrder.Ascending);
        var cases = query.Execute(IsolationLevel.ReadUncommitted).FirstOrDefault();

        if (cases.IsNull())
            throw new HttpNotFoundExecption();

        return Json(cases, JsonRequestBehavior.AllowGet);
    }
}

Yes, this works great. Just return a JsonResult.

Here is an example I am using in production:

 public partial class StudentController : BaseController {
    public StudentController(RESTContext portalContext)
        : base(portalContext) { }

    [HttpGet, Url("organizations/{organizationId?}/students")]
    public virtual JsonResult List(Guid? organizationId) {
        if (organizationId != RESTContext.OrganizationId)
            throw new HttpNotAuthorizedException();

        var query = RESTContext.GetQuery<IQuery<StudentCasesReport>>()
            .Where(x => x.OrganizationId, organizationId)
            .OrderBy(x => x.LastName, SortOrder.Ascending);
        var cases = query.Execute(IsolationLevel.ReadUncommitted);

        return Json(cases, JsonRequestBehavior.AllowGet);
    }

    [HttpGet, Url("organizations/{organizationId?}/students/{studentId?}")]
    public virtual JsonResult Get(Guid? organizationId, Guid? studentId) {
        if (studentId.IsNull())
            throw new HttpNotFoundExecption();

        if (organizationId != RESTContext.OrganizationId)
            throw new HttpNotModifiedException();

        var query = RESTContext.GetQuery<IQuery<StudentCasesReport>>()
            .Where(x => x.OrganizationId, organizationId)
            .Where(x => x.StudentCaseId, studentId)
            .OrderBy(x => x.LastName, SortOrder.Ascending);
        var cases = query.Execute(IsolationLevel.ReadUncommitted).FirstOrDefault();

        if (cases.IsNull())
            throw new HttpNotFoundExecption();

        return Json(cases, JsonRequestBehavior.AllowGet);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文