Tag: asp.net mvc

自定义和集成自己的数据库与mvc5身份

我正在开发一个MVC项目,该项目需要使用Identity创建的身份validation和授权,我的项目数据库还包括应该使用该系统的主要实体,处理这种情况的最佳实践是什么。 我应该根据我的要求自定义身份ApplicationUser。 创建我自己的表(模型)并将它们与身份表集成,我不知道如何做到这一点。 或任何其他解决方案。

ConfidentialClientApplication AcquireTokenSilentAsync始终失败

我正在尝试对微软权限使用OpenIdConnectAuthentication。 我能够进行身份validation,但是当尝试获取访问令牌时,调用失败,希望我重新进行身份validation,我这样做。 我好像从来没有拉过正确的代币。 以下是获取访问令牌的代码。 public async Task GetUserAccessTokenAsync() { string signedInUserID = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; //string signedInUserID = User.Identity.GetUserId(); tokenCache = new MSALSessionCache( signedInUserID, HttpContext.Current.GetOwinContext().Environment[“System.Web.HttpContextBase”] as HttpContextBase); var cachedItems = tokenCache.ReadItems(appId); // see what’s in the cache ConfidentialClientApplication cca = new ConfidentialClientApplication( appId, redirectUri, new ClientCredential(appSecret), tokenCache); try { AuthenticationResult result = await cca.AcquireTokenSilentAsync(scopes.Split(new char[] { ‘ […]

如何在HtmlHelper中调用`EditorExtensions.EditorFor`?

我在CreateView中使用不同的模型,所有模型都inheritance自BaseModel。 调用正确的EditorFor我创建了一个获取Model和实际属性的HtmlHelper。 但我不知道如何调用它。 BaseModel: public abstract class BaseModel { protected IEnumerable PropertyInfoCache { get; set; } protected IEnumerable EnumeratedPropertyCache { get; set; } protected BaseModel() { PropertyInfoCache = this.GetType().GetProperties(); EnumeratedPropertyCache = PropertyInfoCache.Select(p=> new EnumeratedProperty(p.Name,p.GetType())); } public IEnumerable EnumerateProperties() { return EnumeratedPropertyCache; } public object GetPropertyValue(string PropertyName) { var property = PropertyInfoCache.SingleOrDefault(i=>i.Name==PropertyName); if(property!=null) return property.GetValue(this,null); return […]

使用静态DbContext有什么缺点

我是Visual Studio的新手。 我正在开发一个MVC Web项目,我正在使用静态DbContext 。 因为当用户登录时它不是一个简单的网页,他将使用该程序很长一段时间,我希望它快。 使用静态DbContext什么缺点?

将LINQ扩展为SQL生成的类

我已经选择LINQ to SQL作为ASP .NET MVC3项目的ORM框架。 在我面临需要在注册表单中添加额外字段“确认密码”之前,一切都很好。 正如在SO上的一个问题中提到的那样(遗憾的是我目前无法找到它),最好使用接口将生成的LINQ扩展为具有validation属性的SQL类,而不是使用另一个类来存储validation属性。 所以我们走了: public interface IRegTry { [Required] [Email] string EMail { get; set; } [Required] [StringLength(100, ErrorMessage = “Should not exceed 100 symbols”)] string FirstName { get; set; } [Required] string Password { get; set; } } [MetadataType(typeof(IRegTry))] public partial class RegTry : IRegTry { } RegTry类是基于数据库实体由LINQ to SQL生成的类。 […]

Web API令牌身份validation

我将用户凭据从Web应用程序发布到web api,该Web api实现了对用户进行身份validation并使用有效令牌进行响应的提供程序。 这是发布的方法: public TokenModel RequestAPIToken(string username, string password) { var postData = new Dictionary(); postData.Add(“grant_type”, “password”); postData.Add(“username “, username); postData.Add(“password “, password); HttpContent content = new FormUrlEncodedContent(postData); _response = _client.PostAsync(“token”, content).Result; var result = _response.Content.ReadAsAsync().Result; return result; } 这取自web api项目: public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { context.OwinContext.Response.Headers.Add(“Access-Control-Allow-Origin”, new[] { “*” }); var […]

为什么生成的DataBaseManagerController表头是使用ASP MVC 4中的lambda表达式生成的

我为我的解决方案生成了StoreManagerController 。 Visual Studio 2013生成了此类StoreManager/Index.cshtml view @model IEnumerable @{ ViewBag.Title = “Index”; } Index @Html.ActionLink(“Create New”, “Create”) @Html.DisplayNameFor(model => model.Genre.Name) @Html.DisplayNameFor(model => model.Artist.Name) @* @Html.DisplayNameFor(model => model.Title)*@ TITLE @Html.DisplayNameFor(model => model.Price) @foreach (var item in Model) { @Html.DisplayFor(modelItem => item.Genre.Name) @Html.DisplayFor(modelItem => item.Artist.Name) @Html.DisplayFor(modelItem => item.Title) @Html.DisplayFor(modelItem => item.Price) @Html.ActionLink(“Edit”, “Edit”, new { id=item.AlbumId }) […]

ASP.NET MVC StackOverflowException从布局中的xml加载动态菜单

我尝试在我的布局中放置一个动态菜单(从xml加载),但我在PartialController.cs / MainMenu()中有一个StackOverflowException 我不明白为什么我的代码抛出StackOverflowException,因为我没有循环(或者我没有看到它!)。 Layout.cshtml: …. @if (Request.IsAuthenticated) { Html.RenderAction(“MainMenu”, “Partial”); } …. MainMenu.cshtml: @model Geosys.BoT.Portal.POC.Business.Menu @foreach (var item in Model.Nodes) { @item.Name @foreach (var subItem in item.Links) { @Html.ActionLink(subItem.Name, subItem.Action, subItem.Controller) } } PartialController.cs: [ChildActionOnly] public ActionResult MainMenu() { var menu = new Menu { Nodes = new List() }; var xmlData = System.Web.HttpContext.Current.Server.MapPath(“~/Content/navigation.xml”); […]

OWIN Cookie身份validation

我似乎无法让OWIN使用基于Cookie的身份validation。 我已在Startup中将我的OWIN令牌端点配置为: OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = new PathString(“/Token”), Provider = new ApplicationOAuthProvider(PublicClientId), AccessTokenExpireTimeSpan = TimeSpan.FromDays(14), AllowInsecureHttp = true }; app.UseOAuthBearerTokens(OAuthOptions); 我还配置了Cookie身份validation: app.UseCookieAuthentication(new CookieAuthenticationOptions()); 现在,当我点击/token端点时,我得到响应中的承载令牌,并且还在客户端使用令牌设置了cookie。 接下来我有一个用Authorize属性修饰的控制器。 当我尝试访问任何方法时,我得到401 Unauthorized响应,即使cookie随请求一起发送。 似乎OWIN没有尊重cookie进行身份validation。 我在这里遗漏了一些东西,可能是某种类型的配置? 如果我使用bearer token设置Authorization标头,但为什么它只能用于cookie?

System.Runtime.InteropServices.COMException(0x800A1436)

我们正尝试在MVC应用程序上使用Office Interop Services打开驻留在共享驱动器上的Word模板。该解决方案在本地工作,但一旦部署到服务器,就会出现以下消息: The File was not created: System.Runtime.InteropServices.COMException (0x800A1436): This file could not be found ApplicationPool在域用户帐户下运行,该帐户已拥有共享驱动器的权限。 有什么建议吗?