Decoupling ASP.NET MVC 5 Identity to allow implementing a layered application

Here is a quick draft of what I’d try…I would create these layers: Contoso.Core (Class Library) Contoso.Data (Class Library) Contoso.Service (Class Library) Contoso.Web.Framework (Class Library) Contoso.Web (ASP.NET MVC 5.0) Contoso.Core: This layer holds all my entities/classes representing my database TABLES. So for example, I would have a: User.cs class. Product.cs class ProductDetail.cs class Etc.. Some … Read more

How to return a PDF from a Web API application

Some Server side code to return PDF (Web Api). [HttpGet] [Route(“documents/{docid}”)] public HttpResponseMessage Display(string docid) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest); var documents = reader.GetDocument(docid); if (documents != null && documents.Length == 1) { var document = documents[0]; docid = document.docid; byte[] buffer = new byte[0]; //generate pdf document MemoryStream memoryStream = new MemoryStream(); MyPDFGenerator.New().PrintToStream(document, memoryStream); … Read more

How to obtain a list of Users from ASP.NET Identity?

I found out that I wasn’t using the derived ApplicationUser object for anything, so I just went ahead and changed all uses of it for plain old User. Then I just changed ApplicationDbContext definition for the following: public class ApplicationDbContext : IdentityDbContext< User, UserClaim, UserSecret, UserLogin, Role, UserRole, Token, UserManagement> { } And now I … Read more

ASP.NET Web API generate URL using Url.Action

Maybe the closest helper to Url.Action in Web API Controller is the Url.Link method which will generate the URL by Route name, Controller Name, Action Name and the route parameters (if needed). Here is a simple example The default App_start/RouteConfig.cs routes.MapRoute( name: “Default”, url: “{controller}/{action}/{id}”, defaults: new { controller = “Home”, action = “Index”, id … Read more

MVC Bundling and CSS relative URLs

CssRewriteUrlTransform updates the CSS Url with absolute path, saying so if we use – bundles.Add(new StyleBundle(“~/Content/css”).Include(“~/Content/site.css”,new CssRewriteUrlTransform())); and we have following CSS class in “site.css” .Sandy { background-image: url(“Images/Sandy.jpg”); border: 1px solid #c8c8c8; border-radius:4px 4px 4px 4px; box-shadow: 1px 1px 8px gray; background-position:left; background-size:contain; -moz-background-size:contain; -webkit-background-size:contain; -o-background-size:contain; background-repeat:no-repeat; min-height:100px; min-width:100px; display:block; } and following folder … Read more

Basic authentication in ASP.NET MVC 5

You can use this simple yet effective mechanism using a custom ActionFilter attribute: public class BasicAuthenticationAttribute : ActionFilterAttribute { public string BasicRealm { get; set; } protected string Username { get; set; } protected string Password { get; set; } public BasicAuthenticationAttribute(string username, string password) { this.Username = username; this.Password = password; } public override … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)