asp.net-mvc-5

cookie not being set when Expires less than 1 year, on localhost (Chrome and FF)

江枫思渺然 提交于 2019-12-05 06:17:05
I'm facing a problem on localhost, and in Chrome and Firefox , not Edge this code will work ok, and will set the cookie: [HttpPost] public ActionResult Change(string val) { var cookie = new HttpCookie(CookieName) { Value = val, Expires = DateTime.Now.AddYears(1) }; Response.Cookies.Add(cookie); return Content(""); } however if I change the Expires to just 300 days , the cookie won't be sent back in the Request Cookies , (it will still be visible in the Response Cookies for the Change request) Edit: this action is called via jquery ajax ( $.post ); and it used to work maybe half a year ago Have

Error:Upgrade MVC4 to MVC5 in VS2012

夙愿已清 提交于 2019-12-05 06:14:09
I am getting below error after upgrade my project from MVC4 to MVC5. I followed How to Upgrade an ASP.NET MVC 4 and Web API Project to ASP.NET MVC 5 and Web API 2 Assembly 'WebServices.WebApi.External, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' How to solve this issue? I had a similar problem, it was due to me using the _bin_deployableAssemblies This folder

When should I be using AutoMapper and when not

旧城冷巷雨未停 提交于 2019-12-05 06:03:33
I have a Data layer which holds my EF6 DbFirst edmx, repositories, and AutoMappings. I also have a Model layer with a Poco for each auto generated entity in my Data layer. The properties pretty much match exactly except for a few name changes. AutoMapper is installed to my DataLayer only and this is where I set all of my mappings in a config file. At this point I have a mapping from each DataLayer entity to each ModelLayer entity and each ModelLayer entity to each DataLayer entity. Any name changes are specified in the mappings. Since it is setup this way in my repository save methods the

entity type ApplicationUser is not part of the model for the current context

喜夏-厌秋 提交于 2019-12-05 05:52:48
I have an web application in Asp.net with Entity Framework 6 and database first. I'm having issue when it come for the user to connect.Here's my code: Web.config <connectionStrings> <add name="DefaultConnection" connectionString="data source=MyServer\MyDataBase;initial catalog=Cliniciel_WebRV_Master;User Id=XXX;Password=XXXX" providerName="System.Data.SqlClient" /> <add name="Cliniciel_WebRV_MasterEntities" connectionString="metadata=res://*/Models.Entities.Cliniciel_WebRV_Master.csdl|res://*/Models.Entities.Cliniciel_WebRV_Master.ssdl|res://*/Models.Entities.Cliniciel_WebRV_Master.msl

MVC 5 Redirect to Login Page Not Working with OWIN

♀尐吖头ヾ 提交于 2019-12-05 05:30:53
I'm trying to get my head around using OWIN. I have created two MVC 5 projects. One with authentication using Aspnet.Identity and the other started as an empty project. I added the following to the emptyp project: Account controller with a Login action and coresponding view Startup.cs and another partial Startup.cs with public partial class Startup { public void ConfigureAuth(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = "ApplicationCookie", LoginPath = new PathString("/Account/Login") }); } } I have decorated the About action in the Home

How to send AntiForgeryToken (CSRF) along with FormData via jquery ajax

主宰稳场 提交于 2019-12-05 05:22:08
So I want to POST fileUpload along with AntiForgeryToken via AJAX. Here's my code : View @using (Html.BeginForm("Upload", "RX", FormMethod.Post, new {id = "frmRXUpload", enctype = "multipart/form-data"})) { @Html.AntiForgeryToken() @Html.TextBoxFor(m => m.RXFile, new {.type = "file"}) ...rest of code here } <script> $(document).ready(function(){ $('#btnRXUpload').click(function () { var form = $('#frmRXUpload') if (form.valid()) { var formData = new FormData(form); formData.append('files', $('#frmRXUpload input[type="file"]')[0].files[0]); formData.append('__RequestVerificationToken',

How do I check EntityValidationErrors when validation fails?

瘦欲@ 提交于 2019-12-05 04:57:58
I get this message when I try to edit a property in MVC 4 database first project. I'm using the MVC default edit page. "Validation failed for one or more entities. See "EntityValidationErrors" property for more details." Where do I check for validation? Go to your edit function, put a try - catch block and catch the exception - ' DbEntityValidationException ' if you want to see the errors, iterate though the validation errors. here is a simple code example. catch (DbEntityValidationException ex) { foreach (var errors in ex.EntityValidationErrors) { foreach (var validationError in errors

GetExternalLoginInfoAsync always return null when i trying login using Facebook or Google

筅森魡賤 提交于 2019-12-05 04:56:28
I have a problem with OWIN Authentication. I always receive null value from GetExternalLoginInfoAsync() when I trying log in using Facebook or Google. BUT there is some mystical case.. When I open Fiddler. I get correct data using this method. I can't get the reason var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); Thanks in advance!! I have solved my problem by adding this code context.RequestContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true; in the class: private class ChallengeResult : HttpUnauthorizedResult { public ChallengeResult(string

Specify different _Layout.cshtml depending on controller

被刻印的时光 ゝ 提交于 2019-12-05 04:54:17
问题 I created an asp mvc3 project, I want to have a different _Layout.cshtml depending on which controller is selected. This is because with controller 1 it has 2 buttons with the controller2 there will be 3 and with the controller3 there will be 4. Each controller is for a specific type of user, so it depends on the login. How can i link a controller and its views to another Layout.cshtml, right now there is one layout and it's under the Shared folder. Thanks! 回答1: The View should determine the

Does System.Diagnostics.Trace have any performance degredation?

守給你的承諾、 提交于 2019-12-05 04:42:19
I am looking for a simple native .NET error logging solution. I am not interested in using log4net, Elmah or any other logging library. Below is what I am planning on using. My question is performance on my site is paramount and does this flow introduce any performance concerns? Global.asax protected void Application_Start(object sender, EventArgs e) { GlobalFilters.Filters.Add(new HandleExceptionsAttribute()); } Handle Exceptions Attribute: public sealed class HandleExceptionsAttribute : HandleErrorAttribute { private void TraceError(Exception _this) { Trace.TraceError("{0} Exception {1}",