Tag: forms authentication

如何在ASP.Net MVC控制器中正确使用ServiceStack身份validation

我在使用ServiceStack [Authentication]属性在ASP.Net MVC4控制器中工作时遇到问题,即使在正确提交登录详细信息之后,具有该属性的页面/操作方法也会将用户重定向到登录页面。 我遵循了SocialBootstrapApi示例,不同之处在于所有身份validationWeb服务调用都是从控制器进行的: this.CreateRestClient().Post(“/register”, model); 到目前为止我做过的其他事情: 使用我自己的用户会话实现子类化AuthUserSession(与示例没有太大区别,但使用我自己的User表实现) 在我的BaseController上inheritanceServiceStackController,覆盖默认登录URL 使用我的用户会话实现在AppHost中启用Authfunction 注册确实有效,用户身份validation逻辑工作(即使会话不存在),我可以在请求中看到ss-id和ss-pid cookie。 所以我的完整问题清单: 如何使[Authenticate]属性起作用(或者,我做错了什么)? 如何在MVC控制器中保存和重用用户会话? 目前this.UserSession始终为null。 如何注销用户? this.CreateRestClient().Get(“/auth/logout”); 似乎没有用。 更新1: 在我提交任何凭据之前,当我尝试加载安全页面(具有[Authenticate]属性的页面)时,会创建会话cookie( ss-id和ss-pid )。 这是预期的行为吗? 更新2: 我可以看到会话保存在MemoryCacheClient ,但尝试通过this.Cache.Get(SessionKey)在基本控制器中检索它返回null(其中SessionKey如下: urn:iauthsession:1 )

MVC自定义身份validation,授权和角色实现

请耐心等待我提供详细信息… 我有一个MVC站点,使用FormsAuthentication和自定义服务类进行身份validation,授权,角色/成员资格等。 认证 登录有三种方式: (1)电子邮件+别名 , (2)OpenID ,以及(3)用户名+密码 。 这三个人都获得了一个auth cookie并开始一个会话。 前两个是访问者使用(仅限会话),第三个是作者/ admin使用数据库帐户。 public class BaseFormsAuthenticationService : IAuthenticationService { // Disperse auth cookie and store user session info. public virtual void SignIn(UserBase user, bool persistentCookie) { var vmUser = new UserSessionInfoViewModel { Email = user.Email, Name = user.Name, Url = user.Url, Gravatar = user.Gravatar }; […]

HttpWebRequest和C#中的表单身份validation

我是一个系统人员,目前正在做一个兼职的Web开发项目,所以我很新。 我正在尝试为www.portapower.com编写一个http客户端。 对于在网站上发布的某些项目,如果它们符合特定要求,它将打印一条消息。 在尝试访问此页面时: http://www.portapower.com/getbainfo.php?fclasscode=1&code=CB1831B.40H&fbrand=QUNFUg== 该网站将我重定向到默认注册页面: http://www.portapower.com/defaregit.php 这是我编码的片段: CookieContainer myContainer = new CookieContainer(); HttpWebRequest request = (HttpWebRequest) WebRequest.Create(“http://www.portapower.com/” + urlpart); request.Credentials = new NetworkCredential(“****”, “******”); request.CookieContainer = myContainer; request.PreAuthenticate = true; request.Method = “POST”; HttpWebResponse response = (HttpWebResponse) request.GetResponse(); Console.WriteLine(response.StatusCode); Stream resStream = response.GetResponseStream(); Console.WriteLine(resStream.ToString()); 我有用户名和密码,从浏览器使用时工作正常。 请告诉我这是否是访问经过身份validation的页面的正确方法。