forms-authentication

ASP.NET: Why is FormsAuthenticationTicket null after authentication timeout?

你。 提交于 2019-12-02 03:38:26
问题 I'm implementing an authentication timeout detection mechanism per a previous question and answer of mine here. I've implemented an HTTP module that uses the AuthenticateRequest event to run code to capture whether the authentication period has expired. The code to do this is below: public class AuthenticationModule : IHttpModule { #region IHttpModule Members void IHttpModule.Dispose() { } void IHttpModule.Init(HttpApplication application) { application.AuthenticateRequest += new EventHandler

Is there any good reason why the authentication cookie and the session state cookie are two separate cookies?

点点圈 提交于 2019-12-02 03:35:12
Is there any good reason why ASP.NET's session state cookie and the Forms Authentication cookie are two separate cookies? What if I want to "tie" them to each other? Is it possible in an elegant way? Right now, I am stuck with the following solution, which works, but is still ugly: [Authorize] public ActionResult SomeAction(SomeModel model) { // The following four lines must be included in *every* controller action // that requires the user to be authenticated, defeating the purpose of // having the Authorize attribute. if (SomeStaticClass.WasSessionStateLost/*?*/) { FormsAuthentication

Is there any good reason why the authentication cookie and the session state cookie are two separate cookies?

五迷三道 提交于 2019-12-02 03:30:37
问题 Is there any good reason why ASP.NET's session state cookie and the Forms Authentication cookie are two separate cookies? What if I want to "tie" them to each other? Is it possible in an elegant way? Right now, I am stuck with the following solution, which works, but is still ugly: [Authorize] public ActionResult SomeAction(SomeModel model) { // The following four lines must be included in *every* controller action // that requires the user to be authenticated, defeating the purpose of //

ServiceStack API documentation in Swagger-UI behind the closed doors

元气小坏坏 提交于 2019-12-02 00:26:45
问题 I want to allow access to swagger-ui and metadata only if user is authenticated (forms auth) on our web app, but I want to allow API access all the time (API have some public methods and some which require basic auth). So what I did is I added this route prefix for API: public override RouteAttribute[] GetRouteAttributes(Type requestType) { var routes = base.GetRouteAttributes(requestType); routes.Each(x => x.Path = "/API" + x.Path); return routes; } And: ServiceRoutes = new Dictionary<Type,

Membership.GetUser().ProviderUserKey always returns null

强颜欢笑 提交于 2019-12-01 22:47:26
问题 I've recently started using ASP.NET Forms Authentication and Membership. I created a C# project in Visual Studio, which automatically created pages like "/Account/Login.aspx". I then followed an example for installing aspnet_* tables to my SQL Server database, and I've been able to use the <asp:CreateUserWizardStep> control to create a user. I've then been able to login as this user, and the logged in username appears when calling <asp:LoginName> However, when I call the following in my C#

Programmatically enable or disable anonymous authentication in IIS

China☆狼群 提交于 2019-12-01 21:47:14
I have a web application and I need to provide its users the option to switch login method from FormsAuth to WindowsAuth. I managed to change the web.config file via code: Configuration config = WebConfigurationManager.OpenWebConfiguration(Url.Content("~")); AuthenticationSection auth = ((AuthenticationSection)(config.SectionGroups["system.web"].Sections["authentication"])); auth.Mode = AuthenticationMode.Windows; // Or Forms if I want to. config.Save(); But the problem is, when I use FormsAuth, I need the Anonymouse Authentication option to be turned on, and when I use WinAuth, I need it to

ServiceStack API documentation in Swagger-UI behind the closed doors

眉间皱痕 提交于 2019-12-01 21:33:49
I want to allow access to swagger-ui and metadata only if user is authenticated (forms auth) on our web app, but I want to allow API access all the time (API have some public methods and some which require basic auth). So what I did is I added this route prefix for API: public override RouteAttribute[] GetRouteAttributes(Type requestType) { var routes = base.GetRouteAttributes(requestType); routes.Each(x => x.Path = "/API" + x.Path); return routes; } And: ServiceRoutes = new Dictionary<Type, string[]> { { typeof(AuthenticateService), new[] { "/api/auth", "/api/auth/{provider}" } }, } And this

How can I create a local user profile for the anonymous user of an ASP.Net MVC application under IIS 7?

点点圈 提交于 2019-12-01 20:17:23
I've been experimenting with ASP.Net MVC, and have come across a problem that is probably not specifically MVC related. But I cannot get the authentication in the default MVC application (the one created by the wizard when you create a new MVC project) to work properly under IIS 7 on Windows 7. If I run under the Visual Studio environment, it works, but if I switch the settings to run under IIS instead, I get the following exception trying to submit the login or registration: Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path.

Keeping user logged in - FormsAuthentication

╄→гoц情女王★ 提交于 2019-12-01 20:13:32
I am having the hardest time figuring this out. I am using FormAuthentication. When a user logs in and they check remember me, I want to the user to stay logged in for 24 hours. The problem is, no matter what I do the user is automatically logged out after like 30 minutes. We the user selected remember me, I set a persistent cookie to expire 24 hours later. I can see the cookie in the browser options and the expiration is correct. If I leave the site and go back in say an hour. The user is logged out...... He is some code snippets of what I have. bool IsValid = Membership.ValidateUser

Forms Authentication across virtual directories

混江龙づ霸主 提交于 2019-12-01 20:00:52
I am trying to share forms auth from a root application to a sub application running in a virtual directory. I am having trouble with authentication in the subsite. In the parent application everything works as expected. I have the following setup: Parent application: URL : http://localhost:1336/ <forms loginUrl="~/account/sign-in" protection="All" timeout="30" name=".MYAPPLICATION" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="true" defaultUrl="/" /> Virtual Directory: URL : http://localhost:1336/subsite <forms loginUrl="/account