简体   繁体   English

ASP.NET MVC5登录和聊天

[英]ASP.NET MVC5 Login & Chat

So I am using the SignalR to create a chat application. 因此,我正在使用SignalR创建聊天应用程序。 I have a single page chat working Ok, but I need to implement the login so that only users can chat, and non-users get redirected to login page. 我可以进行单页聊天,但是我需要实现登录,以便只有用户可以聊天,并且非用户可以重定向到登录页面。 Basically if you don't have a login I want you only to be able to get to the login page. 基本上,如果您没有登录名,我希望您只能进入登录页面。

This tutorial shows how to setup login, but it doesn't go into how to restrict access to pages. 教程显示了如何设置登录名,但没有涉及如何限制对页面的访问。

Bonus points if you point me in the right direction for grabbing the username from JavaScript for the chat. 如果您向正确的方向指示我,以便从JavaScript中获取用户名进行聊天,则可以得到加分。

Sounds like you want the [Authorize] attribute. 听起来好像您想要[Authorize]属性。 Check out this older post on SO and this MSDN post to get you started. 在SOMSDN 查看此较早的 帖子以使您入门。


Decorate your controller or action with the attribute like this 用这样的属性装饰您的控制器或动作

[Authorize]
public class AccountController : Controller
{
    //only authorized users can access this controller        
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM