我有一个需要经过身份验证的用户ID的应用程序,可以与提交的表单一起插入到表中。我使用下面的代码:
var userId = Int32.Parse((string) Membership.GetUser().ProviderUserKey);
但它给了我错误:
Access denied creating App_Data subdirectory
Description: For security reasons, the identity 'IIS APPPOOL\DefaultAppPool' (under which this web application is running), does not have permissions to create the App_Data subdirectory within the application root directory. ASP.NET stores the Microsoft SQL Express Database file used for services such as Membership and Profile in the App_Data subdirectory of your application.
我没有创造任何东西。我只想获取当前登录用户的UserId。当我得到名称时,它可以工作,代码如下:
var userName = (User.Identity.IsAuthenticated) ? User.Identity.Name : "";
我需要UserId,因为这是我用作UserProfile表的外键约束。
在控制器的Create方法中,我将其指定为:
serialnumber.UserId = userId;
...
db.SerialNumbers.Add(serialnumber);
如何获取当前用户的UserId?