Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

asp.net mvc - How to solve MVC 5 Update and Delete Error

I have built MVC 5 Web application in .net 4.7.2. It runs fine in my local machine. Update and Delete commands were failing, which I have now sorted out thanks to this post: DELETE/PUT verbs result in 404 Not Found in WebAPI, only when running locally, I added this line to the web.config and all the CRUD now works:

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0

However, when I publish the application to my hosting server it breaks at this line in the web.config. When I remove the line only Create and Retrieve data works, but Update and Delete fails with the error:

Object reference not set to an instance of an object.

at this line in the Index view: Line 40: @For Each item In Model

I understand this is because the model is null/nothing at this point.

This is my delete function showing where the error starts...

    Public Function Delete(ByVal id As Integer) As ActionResult

        Dim Client As HttpClient = New HttpClient()
        Client.BaseAddress = New Uri(myWeb & "AppMenuCRUD")

        Dim APIConsumer = Client.DeleteAsync("AppMenuCRUD/" & id.ToString())
        APIConsumer.Wait()

        Dim Result = APIConsumer.Result << failure here: Error 404

        If Result.IsSuccessStatusCode Then
            Return RedirectToAction("Index")
        End If

        Return View("Index")

    End Function

The hosted server is running Windows Server 2016, .Net 4.7.2. I have enabled read/write to the website folder.

This is my IIS Settings in the hosting server:

enter image description here

UPDATES:

  1. Having looked further into this, my hosting server is now updated to .net 4.8 and everything now just fails. I am now not able to even load the index view page. It breaks at the same line 40 as above.
  2. In IIS, my application pool is set to integrated, .net 4.0. I cannot see anything higher from the dropdown list.
  3. In IIS, I have nothing filtered in the list of HTTP Verbs, which I believe means it should accept anything.

UPDATE 2

  1. After the updates to .net 4.8, I am now getting a new error

Lock Violation

I have enabled everything in the IIS, including changing all the ASP Configurations from Read Only to Read/Write.

I'm fearing I may introduce vulnerabilities to the VPS...

Is there anything else I need to do to get this to work?

question from:https://stackoverflow.com/questions/65649759/how-to-solve-mvc-5-update-and-delete-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Sometimes you need to update manually the Web.config when you change the target framework, please double check those lines:

<system.web>
    <compilation debug="true" targetFramework="4.8">
    <httpRuntime targetFramework="4.8" />
...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...