在Visual Studio 2015中,我創建了一個新的ASP.NET空白網站。我想嘗試this sample shopping cart。我添加了一個非常簡單的index.html:在Visual Studio 2015的簡單網頁中不允許HTTP POST(405.0錯誤)
<!DOCTYPE html>
<html>
<head>
<title>Winery</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="css/style.css" media="screen" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.shop.js"></script>
</head>
<body>
<div id="site">
<header id="masthead">
<h1>Winery <span class="tagline">Wines for web developers since 1999</h1>
</header>
<div id="content">
<div id="products">
<ul>
<li>
<div class="product-image">
<img src="images/wine1.jpg" alt="" />
</div>
<div class="product-description" data-name="Wine #1" data-price="5">
<h3 class="product-name">Wine #1</h3>
<p class="product-price">€ 5</p>
<form class="add-to-cart" action="cart.html" method="post">
<div>
<label for="qty-1">Quantity</label>
<input type="text" name="qty-1" id="qty-1" class="qty" value="1" />
</div>
<p><input type="submit" value="Add to cart" class="btn" /></p>
</form>
</div>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>
當我按一下按鈕,我得到這個錯誤:
HTTP Error 405.0 - Method Not Allowed
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
據說這是在cart.html頁面發佈一個項目。 (我可以發佈cart.html的代碼,但我認爲錯誤發生在該頁面之前)如果我只是打開Windows資源管理器並找到index.html並在Chrome中手動打開它,然後單擊按鈕-POST WORKS FINE-,但由於它不在VS2015中(也不是我的Azure Web應用程序服務)。
當我在本地測試站點時,在VS中該進程顯示'iisexpress.exe'正在運行,因此我假設IIS Express默認提供頁面服務。我對這個項目的web.config是默認的,看起來像這樣:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
</configuration>
在網上我看到POST可以默認禁用期待..這是真的?如果是這樣,我認爲很多人會有這個問題。我不敢相信我已經很難找到這個看似簡單的問題的答案。
另外,正如我剛纔提到的,我將它發佈到AZURE Web應用程序服務,因此我認爲在發佈時,任何對IIS配置文件的本地更改都不會改變任何內容。我想我需要更改web.config以使其在Azure中正常工作。
我看過this post以及「研究工作」部分中的所有鏈接。沒有。當我輸入這個內容時,我看到了所有'類似的問題'。他們似乎相關,但沒有解決方案爲我工作。
我很感激幫助。