asp.net-mvc-5

what are the circumstances of using .Wait() when calling async methods

六月ゝ 毕业季﹏ 提交于 2019-12-06 07:45:55
I have the following async long running method inside my asp.net mvc-5 web application :- public async Task<ScanResult> ScanAsync(string FQDN) { // sample of the operation i am doing var c = await context.SingleOrDefaultAsync(a=>a.id == 1); var list = await context.Employees.ToListAsync(); await context.SaveChangesAsync(); //etc.. } and i am using Hangfire tool which support running background jobs to call this async method on timely basis, but un-fortuntly the hangefire tool does not support calling async methods directly . so to overcome this problem i created a sync version of the above

Infinite re-direct loop after AAD Authentication when redirect is specified

亡梦爱人 提交于 2019-12-06 07:40:00
If I specify a redirect URI in my OpenIdConnectAuthenticationOptions like so app.UseOpenIdConnectAuthentication( new OpenIdConnectAuthenticationOptions { ClientId = clientId, Authority = Authority, PostLogoutRedirectUri = postLogoutRedirectUri, RedirectUri = redirectUri, Notifications = new OpenIdConnectAuthenticationNotifications() { AuthenticationFailed = context => { context.HandleResponse(); context.Response.Redirect("/Error?message=" + context.Exception.Message); return Task.FromResult(0); } } }); Then I get an infinite re-direct loop. This only happens though when i put it on and

How to set the NameClaimType in an ASP.Net MVC 5 site?

别等时光非礼了梦想. 提交于 2019-12-06 07:23:08
问题 I've created an ASP.Net MVC 5 site using Microsoft's "On-Premises" Organization Account Authentication mechanism. This is ultimately configured to point to my companies ADFS infrastructure. I'm getting back all the configured claims. However, at runtime, the ClaimsIdentity.Name is blank. This is because the ClaimsIdentity.NameClaimType, by default, appears to be: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name However, I want the ClaimsIdentity.Name to me mapped to: http://schemas

MVC 5 + $Post() function not working after hosted on server

可紊 提交于 2019-12-06 07:22:23
I have developed an application in MVC5. Onclick of a link on the View below code gets invoked - // Code in View File $.post('../ControllerName/FunctionName', //this is your url { id: image, }, function (data) { alert("Successfully published"); } ).error(function () { alert("Failed to publish"); }); //Code in Controller [HttpPost] public void ISPPDF(string id) {} Issue that i am facing is the ISPPDF() function gets invoked when i run it through visual studio.However after i hosted my application on server it does not seem to call the function.. I feel there is some issue with the path i have

Passing Model data from View to Controller and using its values

南楼画角 提交于 2019-12-06 06:53:14
问题 I'm trying to send data from the view and use it in the controller to construct a filename for an upload file feature I am working on, my code is below. Controller // GET: File [Authorize(Roles = "Admin, Lecturer")] public ActionResult Index() { foreach (string upload in Request.Files) { if (Request.Files[upload].FileName != "") { string path = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/uploads/"; string filename = Path.GetFileName(Request.Files[upload].FileName); Request.Files[upload

How do I change the url in MVC 5?

丶灬走出姿态 提交于 2019-12-06 06:19:47
I am trying to change a URL in MVC 5 from "Master" to "Master-Franchise" & I thought the following would work but the URL is still just "Master". // GET: Master-Fanchise [Route("Master-Fanchise")] public ActionResult Master() { return View(); } Use ActionName attributes which allows you to give action name for controller method regardless of method name. [ActionName("Master-Fanchise")] public ActionResult Master() { return View(); } Have you enabled attribute routing as it is not turned on by default public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes

There is already an object named '__MigrationHistory' in the database

二次信任 提交于 2019-12-06 06:03:15
问题 When I tried to execute SQLQuery (generated by Update-Database -Verbose -f -Script locally in Visual Studio) on remote database, I saw the following error returned by SQL Server Management Studio: Msg 2714, Level 16, State 6, Line 1 There is already an object named '__MigrationHistory' in the database. How to solve this? 回答1: __MigrationHistory is an auto-generated table used by EF to track what upgrades/patches it has applied to the database. EF is completely aware of that table and handles

MVC5 Web app using ADFS On-Premises Organizational Auth and Visual Studio 2013 localhost development

我与影子孤独终老i 提交于 2019-12-06 05:42:27
I am trying to create an MVC5 Web Application configured to use the On-Premises Organizational Authenticated Option (ADFS) as described Here by Vittorio Bertocci First, I create new MVC project. Then I change the Authentication to On-Premises. Set the On-Premises Authority to my ADFS federation metadata Endpoint. I checked to make sure the federation metadata xml could be reached and it was. I leave the App ID URI field blank accepting the default value. I ve done both, provided a value and left blank. I then configured my relying party app manually. Setting the relying party WS-Federation

ModelState is coming up as invalid?

偶尔善良 提交于 2019-12-06 05:40:59
I'm working on a MVC5 Code-First application. On one Model's Edit() view I have included [Create] buttons to add new values to other models from within the Edit() view and then repopulate the new value within DropDownFors() on the Edit() . For this first attempt, I am passing a model_description via AJAX to my controller method createNewModel() : [HttpPost] public JsonResult createNewModel(INV_Models model) { // model.model_description is passed in via AJAX -- Ex. 411 model.created_date = DateTime.Now; model.created_by = System.Environment.UserName; model.modified_date = DateTime.Now; model

asp.net mvc: directly assign value to model inside razor view

吃可爱长大的小学妹 提交于 2019-12-06 05:12:17
问题 I have below snippet inside my Create razor View: @Html.EditorFor(model => model.UnitPrice) trying to directly set UnitPrice using statement like this: @Model.UnitPrice = 100; I got something like null pointer exception : Object reference not set to an instance of an object. How can I assign constant value to a field before posting to create post method? 回答1: You need to set the value of the property in the model before you pass the model to the view. Assuming your model is public class