locked
When I am getting records by using Web Api and Code First model ,it showing below errors can you please help me. RRS feed

  • Question

  • User-1419511951 posted

    This is my source code:-- SpellServices.cs:- using System; using System.Collections.Generic; using System.Linq; using QFT_POMS_SVC.Domain.POMS; using System.Web.Http; namespace QFT_POMS_SVC.DAL.POMS { public class SpellServices : ISpellServices { private DBMapper _dbContext; private Result _result; public IList<distributorproductmapping> GetAllDistributorsOp() { var query = from d in _dbContext.DistributorProductMappingRepository select d; return query.ToList(); } public int SaveDistributordetails(int id,DistributorProductMapping items) { DistributorProductMapping DPM = new DistributorProductMapping(); DPM.DistributorId = items.DistributorId; DPM.ProductId = items.ProductId; DPM.Rank = items.Rank; DPM.SKU = items.SKU; DPM.StockStatus = items.StockStatus; DPM.UnitPrice = items.UnitPrice; DPM.UpdatedBy = items.UpdatedBy; DPM.UpdatedDate = items.UpdatedDate; DPM.WholeSaleExpected = items.WholeSaleExpected; DPM.WholeSaleReceived = items.WholeSaleReceived; DPM.MSRPExpected = items.MSRPExpected; DPM.MSRPReceived = items.MSRPReceived; DPM.CreationDate = items.CreationDate; DPM.CreatedBy = items.CreatedBy; DPM.UpdatedDate = items.UpdatedDate; DPM.UpdatedBy = items.UpdatedBy; DPM.Comment = items.Comment; DPM.HasTierPrices = items.HasTierPrices; // _dbContext.DistributorProductMappingRepository.AddRange(items); return _dbContext.SaveChanges(); } public int Update(int Id,DistributorProductMapping obj) { // DistributorProductMapping obj1 = new DistributorProductMapping(); // DistributorProductMapping obj1 = _dbContext.DistributorProductMappingRepository.SingleOrDefault(x => x.Id==1); var obj1 = _dbContext.DistributorProductMappingRepository.FirstOrDefault(x => x.Id == Id); obj1.DistributorId =obj.DistributorId; obj1.ProductId = obj.ProductId; obj1.SKU = obj.SKU; obj1.StockStatus = obj.StockStatus; obj1.UnitPrice = obj.UnitPrice; obj1.deleted = obj.deleted; obj1.Rank = obj.Rank; obj1.DiscountExpected = obj.DiscountExpected; obj1.DiscountReceived = obj.DiscountReceived; obj1.WholeSaleExpected = obj.WholeSaleExpected; obj1.WholeSaleReceived = obj.WholeSaleReceived; obj1.MSRPExpected = obj.MSRPExpected; obj1.MSRPReceived = obj.MSRPReceived; obj1.CreationDate = obj.CreationDate; obj1.CreatedBy = obj.CreatedBy; obj1.UpdatedDate = obj.UpdatedDate; obj1.UpdatedBy = obj.UpdatedBy; obj1.Comment = obj.Comment; obj1.HasTierPrices = obj.HasTierPrices; return _dbContext.SaveChanges(); } public int Delete(int Id) { DistributorProductMapping obj = (from x in _dbContext.DistributorProductMappingRepository where x.Id == Id select x).FirstOrDefault(); obj.deleted = true; return _dbContext.SaveChanges(); } public int GetAllDistributorlist(int id) { DistributorProductMapping obj = (from x in _dbContext.DistributorProductMappingRepository where x.Id == id select x).SingleOrDefault(); //DistributorProductMapping obj1 = new DistributorProductMapping(); DistributorProductMapping obj2 = _dbContext.DistributorProductMappingRepository.SingleOrDefault(x => x.Id==id); return _dbContext.SaveChanges(); } } } ISpellServices.cs using System.Collections.Generic; using QFT_POMS_SVC.Domain.POMS; namespace QFT_POMS_SVC.DAL.POMS { public interface ISpellServices { int SaveDistributordetails(int Id, DistributorProductMapping items); int Update(int Id,DistributorProductMapping obj); int Delete(int Id); int GetAllDistributorlist(int id); } } SpellController.cs:-- using QFT_POMS_SVC.DAL.POMS; using QFT_POMS_SVC.Domain.POMS; using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Web.Http; using System.Web.Http.Cors; namespace QFT_POMS_SVC.Controllers { [RoutePrefix("Spell")] [EnableCors(origins: "*", headers: "*", methods: "*")] public class SpellController : ApiController { private readonly ISpellServices _poService; public SpellController(ISpellServices poService) { this._poService = poService; } [HttpPost] [Route("AddTestEvent")] public HttpResponseMessage AddTestEvent(int PurchaseOrderId) { HttpResponseMessage httpResponse = null; return httpResponse; } [HttpPost] [Route("SaveDistributordetails")] public HttpResponseMessage SaveDistributordetails(int Id) { var response = _poService.SaveDistributordetails(1,new DistributorProductMapping()); HttpResponseMessage httpResponse = null; if (response == null) { httpResponse = Request.CreateResponse(HttpStatusCode.InternalServerError, response); return httpResponse; } else if (response != 0) { httpResponse = Request.CreateResponse(HttpStatusCode.BadRequest, response); return httpResponse; } return Request.CreateResponse(HttpStatusCode.OK, response); } [HttpPut] [Route("Update")] public HttpResponseMessage Update(int Id,DistributorProductMapping obj) { var response = _poService.Update(1,obj); HttpResponseMessage httpResponse = null; if(response==null) { httpResponse = Request.CreateResponse(HttpStatusCode.InternalServerError, response); return httpResponse; } else if(response!=0) { httpResponse = Request.CreateResponse(HttpStatusCode.BadRequest, response); return httpResponse; } return Request.CreateResponse(HttpStatusCode.OK, response); } [HttpDelete] [Route("Delete")] public HttpResponseMessage Delete(int Id) { var response = _poService.Delete(Id); HttpResponseMessage httpResponse = null; if(response==null) { httpResponse = Request.CreateResponse(HttpStatusCode.InternalServerError, response); return httpResponse; } else if(response!=0) { httpResponse = Request.CreateResponse(HttpStatusCode.BadRequest, response); return httpResponse; ; } return Request.CreateResponse(HttpStatusCode.OK, response); } [HttpGet] [Route("GetAllDistributorlist")] public HttpResponseMessage GetAllDistributorlist(int Id) { var response = _poService.GetAllDistributorlist(1); HttpResponseMessage httpResponse = null; if (response == null) { httpResponse = Request.CreateResponse(HttpStatusCode.InternalServerError, response); return httpResponse; } else if (response != 0) { httpResponse = Request.CreateResponse(HttpStatusCode.BadRequest, response); return httpResponse; ; } return Request.CreateResponse(HttpStatusCode.OK, response); } } } </distributorproductmapping>

    Friday, July 12, 2019 7:23 AM

All replies

  • User475983607 posted

    When asking questions include source code as well as the error message that reproduces the issue.

    It seems you are requesting a file with an extension and it not clear why.

    Friday, July 12, 2019 10:04 AM
  • User-1419511951 posted

    <div class="content-container">

    HTTP Error 404.7 - Not Found

    The request filtering module is configured to deny the file extension.

    </div> <div class="content-container">

    <fieldset>

    Most likely causes:

    • Request filtering is configured for the Web server and the file extension for this request is explicitly denied.
    </fieldset>

    </div> <div class="content-container">

    <fieldset>

    Things you can try:

    • Verify the configuration/system.webServer/security/requestFiltering/fileExtensions settings in applicationhost.config and web.config.
    </fieldset>

    </div> <div class="content-container">

    <fieldset>

    Detailed Error Information:

    <div id="details-left">
    Module    RequestFilteringModule
    Notification    BeginRequest
    Handler    StaticFile
    Error Code    0x00000000
    </div> <div id="details-right">
    Requested URL http://localhost :/Spell/GetAllDistributorlist/Controllers/SpellController.cs
    Physical Path   ESpellController.cs
    Logon Method    Not yet determined
    Logon User    Not yet determined
    Request Tracing Directory    C:\Users\unic\Documents\IISExpress\TraceLogFiles\QFT_POMS_SVC
    <div class="clear"></div> </div></fieldset>

    </div> <div class="content-container">

    <fieldset>

    More Information:

    This is a security feature. Do not change this feature unless the scope of the change is fully understood. If the file extension for the request should be allowed, remove the denied file extension from configuration/system.webServer/security/requestFiltering/fileExtensions.

    View more information »

    </fieldset>

    </div>

    Friday, July 12, 2019 11:20 AM
  • User475983607 posted

    This is a duplicate thread.

    https://forums.asp.net/p/2157689/6270090.aspx?When+I+am+getting+records+by+using+Web+Api+and+Code+First+model+it+showing+below+errors+can+you+please+help+me+

    It looks like you are trying to request a cs file directly which is simply not possible.  

    http://localhost :/Spell/GetAllDistributorlist/Controllers/SpellController.cs

    In Web API a controller action is requested which has the would look like. 

    http://localhost:1234/Spell/Action

    Perhaps going through a few basic tutorials before moving forward? 

    https://docs.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

    Or explain what you are trying to do and include source code.

    Friday, July 12, 2019 1:08 PM
  • User283571144 posted

    Hi kondal777,

    According to your other thread, you are facing the 404.7 issue. The error says you use "http://localhost :/Spell/GetAllDistributorlist/Controllers/SpellController.cs" url to call the web api action method.

    But I found you have set the API route with spell and each action has its own route. Like "AddTestEvent", "SaveDistributordetails", "Update".

    I suggest you could try to use"http://localhost/Spell/SaveDistributordetails" to call web API method.

    More details about web API route, you could refer to below article:

    https://docs.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2 

    Best Regards,

    Brando

    Monday, July 15, 2019 2:00 AM