forms-authentication

SetAuthCookie Setting Cookie, but not IsAuthenticated on Subsequent Requests

◇◆丶佛笑我妖孽 提交于 2019-12-13 18:02:52
问题 I have some code where we create an authentication ticket. After creating the ticket, we call SetAuthCookie to set the cookie such as: FormsAuthentication.SetAuthCookie(username, true); Response.Redirect("/", true); If I check on the root page to see if the user is authenticated, it returns false. However, if I hard code the username in and do: FormsAuthentication.GetAuthCookie("jason", true).value); I get the appropriate cookie value. So, the cookie exists. But the name and the flag are not

User.identity .name is empty

那年仲夏 提交于 2019-12-13 17:42:09
问题 I am getting user.identity.name empty in web application using forms authentication after authenticating through memberships. I redirect it to other form but how to keep track of which user is logged in, i am not using session. Is there another way? MembershipUser oCurrentUser = Membership.GetUser(); Response.Write(oCurrentUser.UserName); In this also it is giving me nullreference exception ,though it is validating properly bCheckUser = Membership.ValidateUser(txtUserName.Text, txtPassword

how to make masterPage contents visible based on role?

吃可爱长大的小学妹 提交于 2019-12-13 16:06:12
问题 I am developing an application with masterPage. I want to put loginStatus, LoginName controls into masterPage. now, I want these loginStatus and LoginName controls be visible only if the user is admin. (admin will exclusively navigate to login page and no Login/logout link, logged in username should be shown for non-admins) how can I achieve this? 回答1: There is a LoginView, which supports roles: <asp:LoginView ID="LoginView1" runat="server"> <RoleGroups> <asp:RoleGroup Roles="Admin"> </asp

Authentication to a WCF service not maintained using SetAuthCookie and a full .net client but works with silverlight

你离开我真会死。 提交于 2019-12-13 15:21:47
问题 I've setup a site with forms authentication and AspNetCompatibility enabled. The actual client is a silverlight application, and works fine, however I want to unit test the application separately using normal .net to exercise the service (live system for methods without side-effects). However, when I stop using Silverlight and start using full .net it doesn't remain authenticated In a web service I have: [OperationContract] public bool Login(string Username, string Password, bool isPersistent

How to determine which authentication method is used?

有些话、适合烂在心里 提交于 2019-12-13 14:51:55
问题 I was wondering: How can i determine which authentication method is in use? For example I want to execute a code if my Authentication is based on FORMS authentication and not if it's WINDOWS Authentication. 回答1: You can check what's on the web config using configuration manager ConfigurationManager.GetSection("system.web/authentication"); 回答2: You can retrieve a string property called AuthenticationType on your user's identity object: User.Identity.AuthenticationType . More documentation here

MVC5 Forms authentication not working

我的梦境 提交于 2019-12-13 12:17:06
问题 I'm very new to .NET and security. I've chosen to implement Forms authentication (correct me if I should use something else). From what I gathered on the internet, I did the following, but it's not working: Web.config <authentication mode="Forms"> <forms loginUrl="~/Home/Index" timeout="30" /> </authentication> HTTPPost ajax Login method: [HttpPost] public ActionResult Login(LoginInputModel loginModel) { if (ModelState.IsValid) { var success = UserService.Login(loginModel.Password, loginModel

howto get the user id from a FormsAuthentication page in asp.net MVC?

强颜欢笑 提交于 2019-12-13 08:47:44
问题 i made a webpage which use FormsAuthentication. now i need to get the user id of the user (if a user is logged in) how to get these? i tryed to access it via the FormsAuthentication but there is no method liks: getUserId() any solutions? by the way, i need the id in my controller not in my view. 回答1: if (HttpContext.Current.User.Identity.IsAuthenticated) { var id = HttpContext.Current.User.Identity.Name; // Do stuf... } 来源: https://stackoverflow.com/questions/11134818/howto-get-the-user-id

Retrieving the current logged in user's Id in a class library outside of an ASP.NET Webforms App using forms authentication

倾然丶 夕夏残阳落幕 提交于 2019-12-13 07:11:07
问题 Currently in every one of my model classes I am doing the following in the constructor. public Product() { CreatedBy = System.Threading.Thread.CurrentPrincipal.Identity.Name; ModifiedBy = System.Threading.Thread.CurrentPrincipal.Identity.Name; } This way when saving/updating records these values will always be set. However, I want to switch my application from using the logged in user's name which the above gets me, to using the logged in user's Id. With forms authentication what is the best

authenticate Lightswitch Odata service that uses forms authentication

廉价感情. 提交于 2019-12-13 06:18:30
问题 I created an OData service using VS Lightswitch with an endpoint like this: http://mydevsite.com/lightswitchapps/mydata/products.svc The service is secured with forms authentication. When I put the url into a browser I am asked for credentials. I want to build a console app in C# to consume the service. But I can't find any examples of how to authenticate. I've worked through this which consumes the Northwind service: http://msdn.microsoft.com/en-us/library/hh868028%28v=vs.103%29.aspx But I

CurrentPrincipal.Identity.IsAuthenticated is true even after signout when FormsAuth cookie domain set manually

﹥>﹥吖頭↗ 提交于 2019-12-13 04:31:28
问题 Refering to sharing cookie in subdomains I implemented jro's answer and it worked for sign in. (sharing the cookie in different sub domains) However with this change effected the signout process. Please refer to the SignOut and SignIn code I shared below. The issue is that in the signout process it does a FormsAuthentication.SignOut and then redirect to the sign in controller, but "System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated" is set to true even though the