Authentication problems after publishing MVC 4 app to azure

后端 未结 3 818
旧时难觅i
旧时难觅i 2020-12-17 21:38

I have a basic ASP.NET MVC 4 site which I am hosting on Azure websites. The authentication is forms authentication and has not been customised from the default template. Eve

3条回答
  •  误落风尘
    2020-12-17 22:08

    After trying dozens of different suggestions from various blog posts, I have found a solution. Adding the InitialiseSimpleMembership attribute to my home controller resolves the problem.

    [InitializeSimpleMembership]
    public class HomeController : Controller
    

    After making this change, I managed several successful publishes without issues. I suspect the reason is that the following line of code in the InitializeSimpleMembershipAttribute constructor needs to run before any calls to User.IsInRole are made:

    WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
    

    I guess the best thing to do would be to run InitializeSimpleMembership in Application_Start.

提交回复
热议问题