在浏览ASP.NET网页API [英] ASP.NET Web Api in Views

查看:122
本文介绍了在浏览ASP.NET网页API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过这个情况的WebAPI创建一个登录页面。

I want to create a login page via webapi with this situations .

我不想使用令牌和..但观点应该是安全的(不是直接调用URL)。

i dont want to use token and.. but the views should be secure (not direct called in URL).

如果该用户是管理员负载view_x。

If the user is Admin load view_x.

如果该用户是员工负载view_y。

If the user is Employee load view_y.

如果用户是学生负担view_z。

If the user is Student load view_z.

请给我建议

推荐答案

我相信你有一个前端的网站,你在谈论的观点装载它利用本网站的API。首先,你可能想在你的web API,用于各类用户的后端定义角色。对于如每个用户都将属于你的数据库一样的学生,管理,员工等。当你的网站被推出便打电话给你的Web API来验证谁是试图登录用户的真实性被称为动作方法定义的角色只有一个。登录是全成后,还应该获取登录从Web API用户的角色信息。当你和你的角色信息然后只需使用如下图所示的开关条款重定向到相应的视图:

I believe you have a front end website which leverages this web API as you are talking about loading of views. Firstly you might want to define roles in your back-end of your web API for various types of users. For e.g. every user will belong to exactly one of the defined roles in your DB like Student, Admin, Employee etc. The action method which is called when your website gets launched will call your web API to validate the authenticity of the user who is trying to login. After the login is successfull it should also fetch the role information of the logged in user from the web API. When you have role information with you then simply use a switch clause as shown below to redirect to appropriate view:

public ActionResult Login()
        {
            //call web api to validate the user credentials
            var role = <call the web api to get the role of the user>;
            switch (role)
            {
                case "Admin" :
                    return View("Admin");
                case "Student" :
                    return View("Student");
                case "Employee" :
                    return View("Employee");
                case "Others" :
                    return View("Others");
            }
        }

希望这有助于!

这篇关于在浏览ASP.NET网页API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆